/*

*/
CommonTestData = function(){

	return {
		
		//holds all the sql query strings and the expected result
		_data : {
			
			//"testOnly" : "1",
			"1" : {

				"preTest" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS LoginSignature";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					//this must be the tbl structure (with the autoincrement, primary key field)
					//var query = "Create Table LoginSignature " +
					//				"(_id integer not null primary key autoincrement, LoginID text, StoreID text, LoginTime text, Signature text)"
					
					//use this table structure for now
					var query = "Create Table LoginSignature " +
									"(LoginID text, StoreID text, LoginTime text, Signature text)"
						,me = this;
					
					this.executeReader(query, crcDB, function(t, r_or_e){
						
						//insert three records
						query = "INSERT INTO LoginSignature (LoginID, StoreID,LoginTime, Signature) VALUES " +
									"(1,1, '23:59:59', 'signature_test')";
						
						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
						query = "INSERT INTO LoginSignature (LoginID, StoreID,LoginTime, Signature) VALUES " +
									"(2,2, '23:59:59', 'signature_test')";

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
						query = "INSERT INTO LoginSignature (LoginID, StoreID,LoginTime, Signature) VALUES " +
									"(3,3, '23:59:59', 'signature_test')";

						me.executeReader(query, crcDB, function(_t, _r_or_e){});						
						
					});
					
				}
				
			   ,"query" : "select LoginID, StoreID, LoginTime, Signature From LoginSignature limit 1"
			   
			   ,"expectedData" : [{"LoginID" : 1, "StoreID" : 1, "LoginTime" : '23:59:59', "Signature" : 'signature_test'}]
		
			   ,"evaluateResult" : function(t, r_or_e, testParams){
					console.log(r_or_e);
					return (
							 r_or_e.rows.length == 1 
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData)
					);
					
			    }
				
			    ,"postTest" : function(){}
			   
			}
		 
			//,"testOnly" : "1a"
		   ,"1a" : {
		   
				"preTest" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS LoginSignature";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					//this must be the tbl structure (with the autoincrement, primary key field)
					//var query = "Create Table LoginSignature " +
					//				"(_id integer not null primary key autoincrement, LoginID text, StoreID text, LoginTime text, Signature text)"
					
					//use this table structure for now
					var query = "Create Table LoginSignature " +
									"(LoginID text, StoreID text, LoginTime text, Signature text)"
						,me = this;
						
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						//insert three records
						query = "INSERT INTO LoginSignature (LoginID, StoreID,LoginTime, Signature) VALUES " +
									"(1,1, '23:59:59', 'signature_test')";

						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = "INSERT INTO LoginSignature (LoginID, StoreID,LoginTime, Signature) VALUES " +
									"(2,2, '23:59:59', 'signature_test')";

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
						query = "INSERT INTO LoginSignature (LoginID, StoreID,LoginTime, Signature) " +
									'select "3", "3", "23:59:59", Signature From LoginSignature';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});						
						
					});				
				}
				
			   ,"query" : 'SELECT * FROM LoginSignature WHERE LoginID = "3"'
			   
			   ,"expectedData" : [{"1" : "1", "1:1" : "1", "Signature" : 'signature_test'}]
		
			   ,"evaluateResult" : function(t, r_or_e, testParams){
					

					return true;
					// return (
							 // r_or_e.rows.length == 1 
						// && HPI.isEqual(this.srData(r_or_e), testParams.expectedData)
					// );
					
			    }
		   
		   }
			
			//,"testOnly" : "1"
			,"2" : {
			
				"preTest" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS preferences";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					

					var query = "create table preferences( _id integer not null primary key autoincrement," +
									"prefname text, intvalue integer, floatvalue x, charvalue text)"
						,me = this;
						
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						query = 'INSERT INTO preferences (prefname, intvalue, floatvalue, charvalue) VALUES ' +
									'("HH Version","","","2.5.2")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){//console.log(_r_or_e);
						});

						query = 'INSERT INTO preferences (prefname, intvalue, floatvalue, charvalue) VALUES ' +
									'("HHPCEnterCheckInOutTime","1","","")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){//console.log(_r_or_e);
						});
						
					});
					
				}

			   ,"query" : "select intValue  from preferences where prefname='HHPCEnterCheckInOutTime'"
			   ,"expectedData" : [{'intValue' : 1}]

				,"evaluateResult" : function(t, r_or_e, testParams){//console.log(r_or_e);
					return (
							 r_or_e.rows.length == 1 
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData)
					);
			    }
				
			}
			//,"testOnly" : "3"
			,"3" : {
				"preTest" : function(){
					//console.log('a')
					this.initDB();

					var query = "DROP TABLE IF EXISTS stores";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "create table stores( _id integer," +
									"chainid text, storenumber text, storename text)"
					
					var me = this;
						
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						query = 'INSERT INTO stores (_id, chainid, storenumber, storename) VALUES ' +
									"(1, '1', '1', 'store 1')";

						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO stores (_id, chainid, storenumber, storename) VALUES ' +
									"(2, '1', '2', 'store 2')";

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
						query = 'INSERT INTO stores (_id, chainid, storenumber, storename) VALUES ' +
									"(3, '2', '3', 'store 3')";
									
						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
					});
					
					
				}
				
				// 
			   ,"query" : "select * from stores where chainid = 1 order by cast(storenumber AS int)"
			   ,"expectedData" : [
					{'_id' : 1, "chainid" : "1", "storenumber" : "1", "storename" : 'store 1'}
				   ,{'_id' : 2, "chainid" : "1", "storenumber" : "2", "storename" : 'store 2'}
			   ]
			   
			   ,"evaluateResult" : function(t, r_or_e, testParams){
				
					return (
							 r_or_e.rows.length == 2 
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData)
					);
			    }
				
			}
			
			//,"testOnly" : "3a"
			,"3a" : {
			
				"preTest" : function(){
					
					this.initDB();
				}
				
			   ,"query" : "select * from stores where chainid = 12345 order by cast(storenumber AS int)"
			   
			   ,"expectedData" : [
					
			   ]
			   
			   ,"evaluateResult" : function(t, r_or_e, testParams){
					
					return (
							 r_or_e.rows.length == 0
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData)
					);
			    }
				
			}
			
			,"11" : {
				"preTest" : function(){
				
					this.initDB();

					var query = "DROP TABLE IF EXISTS SurveyAnswerSession";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "create table SurveyAnswerSession( PushedAnswerID integer," +
									"description text)"
					
					var me = this;
						
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						query = 'INSERT INTO SurveyAnswerSession (PushedAnswerID, description) VALUES ' +
									"(1, 'test 1')";

						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO SurveyAnswerSession (PushedAnswerID, description) VALUES ' +
									"(null, 'test 2')";

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
						query = 'INSERT INTO SurveyAnswerSession (PushedAnswerID, description) VALUES ' +
									"(null, 'test 3')";
									
						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
					});
				}
			   
			   ,"query" : "select * from SurveyAnswerSession where ifnull(PushedAnswerID, '') = ''"
			   
			   ,"expectedData" : [{"PushedAnswerID" : null, "description" : "test 2"}, {"PushedAnswerID" : null, "description" : "test 3"}]
			   
			   ,"evaluateResult" : function(t, r_or_e, testParams){
					
					//console.log(r_or_e);
					return (
					
							 r_or_e.rows.length == 2
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData, false)
						
					);

			    }			   
			}		

			//,"testOnly" : "4"
			,"4" : {
			
				"preTest" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS Chains";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					

					var me = this;
					
					var query = "create table Chains( _id integer not null primary key autoincrement," +
									"chaincode text, chainname text)"

						
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						query = 'INSERT INTO Chains (_id, chaincode, chainname) VALUES ' +
									'(1, "CH1", "Chain 1")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO Chains (_id, chaincode, chainname) VALUES ' +
									'(2, "CH2", "Chain 2")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
					});					
					
				}
				
			   ,"query" : "select distinct Chains._id,Chains.chainname from Chains Inner Join stores On Chains._id = stores.chainid order by chainname"
			   ,"expectedData" : [{'_id' : 1, 'chainname' : 'Chain 1'}, {'_id' : 2, 'chainname' : 'Chain 2'}]
			   
			   ,"evaluateResult" : function(t, r_or_e, testParams){
					//console.log(r_or_e);
					return (
							 r_or_e.rows.length == 2
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData)
					);

			    }
				
			}
			
			//,"testOnly" : ["3", "4", "5"]
			,"5" : {
				"preTest" : function(){
				
					this.initDB();
				}
			   ,"query" : "Select stores._id,stores.storenumber, stores.storename,Chains.chaincode,Chains.chainname From Stores Inner Join Chains On Stores.chainid = Chains._id where Stores._id= 1"
			   //,"query" : "select * from chains"
			   ,"expectedData" : [{"_id" : 1, "storenumber" : "1", "storename" : "store 1", "chaincode" : "CH1", "chainname" : "Chain 1"}]
			   ,"evaluateResult" : function(t, r_or_e, testParams){
					console.log(r_or_e);
					return (
							 r_or_e.rows.length == 1
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData)
					);

			    }
			}

			//,"testOnly" : "6"
			,"6" : {

				"preTest" : function(){
					
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS shistory";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "DROP TABLE IF EXISTS auditsurveys";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					var me = this;

					var query = "CREATE TABLE shistory(answerid int, surveycode text, surveytitle text, visitid int, CanAudit int)";
					this.executeReader(query, crcDB, function(t, r_or_e){

						query = 'INSERT INTO shistory (answerid, surveycode, surveytitle, visitid, CanAudit) VALUES ' +
									'(2, "D", "title D", 2, 1)';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
					
						query = 'INSERT INTO shistory (answerid, surveycode, surveytitle, visitid, CanAudit) VALUES ' +
									'(1, "A", "title A", 1, 1)';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO shistory (answerid, surveycode, surveytitle, visitid, CanAudit) VALUES ' +
									'(1, "B", "title B", 1, 1)';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
						query = 'INSERT INTO shistory (answerid, surveycode, surveytitle, visitid, CanAudit) VALUES ' +
									'(1, "C", "title C", 1, 0)';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});						
						
					});
					 
					query = "CREATE TABLE auditsurveys (auditanswerid integer, answer text)";
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						query = 'INSERT INTO auditsurveys (auditanswerid, answer) VALUES ' +
									'(1, "answer 1")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO auditsurveys (auditanswerid, answer) VALUES ' +
									'(2, "answer 2")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
						query = 'INSERT INTO auditsurveys (auditanswerid, answer) VALUES ' +
									'(3, "answer 3")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
					});
					
				}
				// 
			   ,"query" : "select auditsurveys.*,shistory.answerid,shistory.surveycode,shistory.surveytitle from shistory Inner Join auditsurveys On shistory.answerid == auditsurveys.auditanswerid where shistory.visitid= 1 and shistory.CanAudit = 1"
			   
			   ,"expectedData" : [
					{"auditanswerid" : 1, "answer" : "answer 1", "answerid" : 1, "surveycode" : "A", "surveytitle" : "title A"}
				   ,{"auditanswerid" : 1, "answer" : "answer 1", "answerid" : 1, "surveycode" : "B", "surveytitle" : "title B"}
				]
				
			   ,"evaluateResult" : function(t, r_or_e, testParams){
					//console.log(r_or_e);
					return (
							 r_or_e.rows.length == 2
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData)
					);

			    }			
			}

			,"6a" : {
			
				"preTest" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS Schd_CallSchedule";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "DROP TABLE IF EXISTS Project";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					
					var me = this;
					
					var query = "create table Schd_CallSchedule(ScheduleID int, ProjectId int, StoreID int, DateStart text, DateEnd text," +
									"TargetStart text, TargetEnd text, TimeStart text, TimeEnd text, Status int)"

						
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						query = 'INSERT INTO Schd_CallSchedule (ScheduleID, ProjectId, StoreID, DateStart, DateEnd, TargetStart, TargetEnd, TimeStart, TimeEnd, Status) VALUES ' +
									'(1, 1, 1, "2012-01-01", "2012-01-02", "2012-01-01", "2012-01-02", "1:00", "2:00", 1)';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO Schd_CallSchedule (ScheduleID, ProjectId, StoreID, DateStart, DateEnd, TargetStart, TargetEnd, TimeStart, TimeEnd, Status) VALUES ' +
									'(2, 1, 1, "2012-01-01", "2012-01-02", "2012-01-01", "2012-01-02", "1:00", "2:00", 1)';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
						query = 'INSERT INTO Schd_CallSchedule (ScheduleID, ProjectId, StoreID, DateStart, DateEnd, TargetStart, TargetEnd, TimeStart, TimeEnd, Status) VALUES ' +
									'(3, 2, 3, "2012-01-01", "2012-01-02", "2012-01-01", "2012-01-02", "1:00", "2:00", 1)';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
					});
					
					
					query = "create table Project (ProjectID int, ProjectDescription text)";
					
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						query = 'INSERT INTO Project (ProjectID, ProjectDescription) VALUES ' +
									'(1, "Project 1")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO Project (ProjectID, ProjectDescription) VALUES ' +
									'(2, "Project 2")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
					});
					
				}
				
			   ,"query" : "Select sch.ScheduleID,sch.DateStart,sch.DateEnd,sch.TargetStart,sch.TargetEnd,sch.TimeEnd,sch.TimeStart,sch.Status,p.ProjectDescription,s.storename From Schd_CallSchedule sch Inner Join Project p ON sch.ProjectID = p.ProjectID Inner Join Stores s ON sch.StoreID = s._id WHERE sch.ScheduleID = 3"
			   ,"expectedData" : [{"ScheduleID" : 3, "DateStart" : '2012-01-01', "DateEnd" : '2012-01-02', "TargetStart" : '2012-01-01', "TargetEnd" : '2012-01-02', "TimeEnd" : '2:00', "TimeStart" : '1:00', "Status" : 1, "ProjectDescription" : "Project 2", "storename" : "Store 3"}]
			   ,"evaluateResult" : function(t, r_or_e, testParams){
					
					return (
							 r_or_e.rows.length == 1
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData)
					);

			    }			   
			
			}
			
			,"6b" : {
			
				"preTest" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS Schd_CallScheduleStatusCodes";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "DROP TABLE IF EXISTS Schd_CallSchedule";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					var me = this;

					var query = "CREATE TABLE Schd_CallScheduleStatusCodes(StatusID int, StatusDesc text)";
					this.executeReader(query, crcDB, function(t, r_or_e){

						query = 'INSERT INTO Schd_CallScheduleStatusCodes(StatusID, StatusDesc) VALUES ' +
									'(1,  "Status 1")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
					
						query = 'INSERT INTO Schd_CallScheduleStatusCodes(StatusID, StatusDesc) VALUES ' +
									'(2,  "Status 2")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO Schd_CallScheduleStatusCodes(StatusID, StatusDesc) VALUES ' +
									'(3,  "Status 3")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
					
						
					});
					 
					query = "CREATE TABLE Schd_CallSchedule (ScheduleID integer, StoreID integer, Status integer)";
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						query = 'INSERT INTO Schd_CallSchedule (ScheduleID, StoreID, Status) VALUES ' +
									'(1, 1, 1)';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO Schd_CallSchedule (ScheduleID, StoreID, Status) VALUES ' +
									'(2, 1, 2)';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
						query = 'INSERT INTO Schd_CallSchedule (ScheduleID, StoreID, Status) VALUES ' +
									'(3, 2, 2)';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
					});

				}
				
			   ,"query" : "select distinct stc.StatusID,stc.StatusDesc, sc.ScheduleID, sc.StoreID from Schd_CallScheduleStatusCodes stc left join Schd_CallSchedule sc on sc.Status = stc.StatusID order by stc.StatusDesc"
			   
			   ,"expectedData" : [
					{"StatusID" : 1, "StatusDesc" : "Status 1", "ScheduleID" : 1, "StoreID" : 1}
				   ,{"StatusID" : 2, "StatusDesc" : "Status 2", "ScheduleID" : 3, "StoreID" : 2}
				   ,{"StatusID" : 2, "StatusDesc" : "Status 2", "ScheduleID" : 2, "StoreID" : 1}
				   ,{"StatusID" : 3, "StatusDesc" : "Status 3", "ScheduleID" : null, "StoreID" : null}
				]
				
				,"evaluateResult" : function(t, r_or_e, testParams){

					return (
							 r_or_e.rows.length == 4
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData, false)
					);

			    }				
			
			}
			
			//,"testOnly" : "6c"
			//inner join, then left join works
			,"6c" : {
			
				"preTest" : function(){
				
					this.initDB();

					var query = "drop table if exists Product;";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "create table Product(ProductID int not null primary key, UPC text, ProductName text, ProductDescription text, InternalCode text);"
					this.executeReader(query, crcDB, function(t, r_or_e){});

					
					var me = this;

					var products = [
						'insert into Product(ProductID, UPC, ProductName, ProductDescription, InternalCode) values(17130,"016000338500","Betty Crocker Apple Streusel Muffin Mix","Apple Streusel Muffin Mix","77701");'
					   //,'insert into Product(ProductID, UPC, ProductName, ProductDescription, InternalCode) values(17131,"072486002205","Jiffy Corn muffin mix","Corn muffin mix","77707");'
					   //,'insert into Product(ProductID, UPC, ProductName, ProductDescription, InternalCode) values(17133,"054800052011","Uncle Ben\'s Oriental Fried Rice","Oriental Fried Rice","77717");'					
					];
					for(var i = 0, len = products.length; i < len; i++){
						this.executeReader(products[i], crcDB, function(t, r_or_e){});
					}
					
					var query =  "drop table if exists SurveyProduct;";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					var query = "create table SurveyProduct(StoreID int, SurveyID int, ProductID int, Sequence int);";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var surveyProducts = [
						"insert into SurveyProduct(StoreID, SurveyID, ProductID, Sequence) values(406530,4111,17130,1);"
						//,"insert into SurveyProduct(StoreID, SurveyID, ProductID, Sequence) values(406530,4111,17133,2);"
						//,"insert into SurveyProduct(StoreID, SurveyID, ProductID, Sequence) values(406530,4111,17131,3);"
					];
					for(var i = 0, len = surveyProducts.length; i < len; i++){
						this.executeReader(surveyProducts[i], crcDB, function(t, r_or_e){});
					}
					
					var surveyAnswerSession = [
						"drop table if exists SurveyAnswerSession"
					   ,"create table SurveyAnswerSession (storeid text, surveyid text, surveycode text,ProductID int)"
					   //,"insert into surveyanswersession values('1', '1', '1', 17130)"
					];

					for(var i = 0, len = surveyAnswerSession.length; i < len; i++){
						this.executeReader(surveyAnswerSession[i], crcDB, function(t, r_or_e){});
					}
					
				}
			   
			   ,"query" : "SELECT sp.StoreID as sp_StoreID, sp.SurveyID as sp_SurveyID, sp.ProductID as sp_ProductID, sp.Sequence as sp_Sequence " +
							  ", p.ProductID as p_ProductID, p.UPC as p_UPC, p.ProductName as p_ProductName, p.ProductDescription as p_ProductDescription, p.InternalCode as p_InternalCode " +
							  ", sas.storeid as sas_storeid, sas.surveyid as sas_surveyid, sas.surveycode as sas_surveycode, sas.ProductID as sas_productid " + 
							  " FROM SurveyProduct sp inner join Product p on p.ProductID = sp.ProductID left join SurveyAnswerSession sas on sas.ProductID = sp.ProductID "
			   
			   ,"expectedData" : [
					{'sp_StoreID' : 406530, 'sp_SurveyID' : 4111, 'sp_ProductID' : 17130, 'sp_Sequence' : 1
					  ,'p_ProductID' : 17130,  'p_UPC' : "016000338500", 'p_ProductName' : "Betty Crocker Apple Streusel Muffin Mix", 'p_ProductDescription' : "Apple Streusel Muffin Mix", 'p_InternalCode' : "77701"
					  ,'sas_storeid' : null, 'sas_surveyid' : null, 'sas_surveycode' : null, 'sas_productid' : null
					}
				]
				
				,"evaluateResult" : function(t, r_or_e, testParams){

					return (
							 r_or_e.rows.length == 1
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData, false)
					);

			    }				
			
			}
			
			//left join works
			//,"testOnly" : "6ca"

			,"6ca" : {
				
				"testFn" : function(){
				
					
					this.initDB();
					
					var me = this;
					
					var query = "DROP TABLE IF EXISTS surveys";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					/*
					query = "create table surveys(surveycode int)";					
					this.executeReader(query, crcDB, function(t, r_or_e){});

					query = "insert into surveys(surveycode) VALUES (1)";			
					this.executeReader(query, crcDB, function(t, r_or_e){});

					query = "insert into surveys(surveycode) VALUES (2)";			
					this.executeReader(query, crcDB, function(t, r_or_e){});
					*/
					var query = "DROP TABLE IF EXISTS surveyanswersession";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					
					/*
					query = "create table surveyanswersession(sessionid int, surveycode text)";					
					this.executeReader(query, crcDB, function(t, r_or_e){});

					query = "insert into surveyanswersession(sessionid, surveycode) VALUES (1, '1')";			
					this.executeReader(query, crcDB, function(t, r_or_e){});
					*/
					//surveys:
					var query = "create table surveys (_id integer not null primary key autoincrement, title text, surveycode text, questioncount integer, startdate text, enddate text, mandatory integer, skipable integer, canaudit integer, activationtype integer);"
					this.executeReader(query, crcDB, function(t, r_or_e){});
					//var surveys = [{"_id": "41159", "title": "!Skip to my Lou!", "surveycode": "7257", "questioncount": "5", "startdate": "2011-03-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "41515", "title": "!Survey", "surveycode": "7258", "questioncount": "12", "startdate": "2011-05-02 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "40021", "title": "!test3542", "surveycode": "100123", "questioncount": "3", "startdate": "2010-07-29 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "41692", "title": "05/27/2011 Survey", "surveycode": "7261", "questioncount": "1", "startdate": "2011-05-27 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "40252", "title": "1.0.3.4 test", "surveycode": "100133", "questioncount": "6", "startdate": "2010-09-09 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "44541", "title": "10-2-12 upgrade test", "surveycode": "200024", "questioncount": "0", "startdate": "2012-10-02 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44539", "title": "1002 test", "surveycode": "200017", "questioncount": "0", "startdate": "2012-10-02 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "3"},{"_id": "41592", "title": "42637", "surveycode": "7259", "questioncount": "1", "startdate": "2011-05-10 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "41948", "title": "43381 test", "surveycode": "7265", "questioncount": "1", "startdate": "2011-06-27 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "42206", "title": "44140 Testing", "surveycode": "100152", "questioncount": "4", "startdate": "2011-08-04 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "41738", "title": "6/1/2011 test", "surveycode": "7263", "questioncount": "12", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43738", "title": "A New Product Survey", "surveycode": "100175", "questioncount": "4", "startdate": "2012-05-14 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "1", "activationtype": "null"},{"_id": "44283", "title": "AAATest For Photos", "surveycode": "200011", "questioncount": "0", "startdate": "2012-08-09 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44102", "title": "All Question Type Testing", "surveycode": "200010", "questioncount": "0", "startdate": "2012-07-19 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "43754", "title": "Aloha Sample 1", "surveycode": "100177", "questioncount": "18", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "43755", "title": "Aloha Sample 3", "surveycode": "100178", "questioncount": "20", "startdate": "2012-02-20 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43756", "title": "Aloha Sample 4", "surveycode": "100179", "questioncount": "14", "startdate": "2012-05-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "41052", "title": "Android Photo questions", "surveycode": "7255", "questioncount": "3", "startdate": "2011-02-20 12:00:00.000", "enddate": "2015-02-20 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "null", "activationtype": "null"},{"_id": "41315", "title": "Android Survey #1", "surveycode": "2227", "questioncount": "3", "startdate": "2011-03-29 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "41316", "title": "Android Survey #2", "surveycode": "2228", "questioncount": "2", "startdate": "2011-03-30 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "41317", "title": "Android Survey #3", "surveycode": "2229", "questioncount": "2", "startdate": "2011-03-30 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "41318", "title": "Android Survey #4", "surveycode": "2230", "questioncount": "2", "startdate": "2011-03-30 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44284", "title": "Angie Survey Test 1", "surveycode": "200012", "questioncount": "0", "startdate": "2012-08-09 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44288", "title": "Another Picture Test", "surveycode": "200013", "questioncount": "0", "startdate": "2012-08-09 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "39548", "title": "Chad Test Survey", "surveycode": "100081", "questioncount": "13", "startdate": "2009-01-01 12:00:00.000", "enddate": "2099-01-01 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "43758", "title": "Completion Test Survey", "surveycode": "100180", "questioncount": "2", "startdate": "2012-05-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43253", "title": "copy of (small) test", "surveycode": "100162", "questioncount": "75", "startdate": "2011-07-26 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "42164", "title": "Copy of Books and Mags for question savin", "surveycode": "100149", "questioncount": "14", "startdate": "2011-08-01 12:00:00.000", "enddate": "2015-03-01 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "40037", "title": "Copy of Chad Test Survey", "surveycode": "100126", "questioncount": "10", "startdate": "2009-01-01 12:00:00.000", "enddate": "2099-01-01 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "40880", "title": "Copy Survey Results Test", "surveycode": "7253", "questioncount": "2", "startdate": "2011-01-13 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "40025", "title": "copytest", "surveycode": "100125", "questioncount": "1", "startdate": "2010-07-29 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "1", "activationtype": "null"},{"_id": "43200", "title": "Dashboard Testing Survey", "surveycode": "100160", "questioncount": "3", "startdate": "2011-03-05 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "0", "activationtype": "null"},{"_id": "44064", "title": "Dog Food Brands", "surveycode": "200008", "questioncount": "0", "startdate": "2012-07-12 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43196", "title": "Exit Survey Question Testing", "surveycode": "100159", "questioncount": "19", "startdate": "2012-02-20 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "0", "activationtype": "null"},{"_id": "15767", "title": "Handheld Sample Survey", "surveycode": "43", "questioncount": "6", "startdate": "2006-06-01 12:00:00.000", "enddate": "2030-06-01 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "null", "activationtype": "null"},{"_id": "43773", "title": "Initial Inventory", "surveycode": "199999", "questioncount": "23", "startdate": "2012-05-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43090", "title": "Intelligent Question Testing", "surveycode": "100156", "questioncount": "7", "startdate": "2012-02-07 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "0", "activationtype": "null"},{"_id": "43627", "title": "iPad Attachment Testing", "surveycode": "100164", "questioncount": "5", "startdate": "2012-05-02 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "0", "activationtype": "null"},{"_id": "41691", "title": "Jake's Sample Survey", "surveycode": "7260", "questioncount": "18", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "41722", "title": "Jake's Sample Survey #2", "surveycode": "7262", "questioncount": "15", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "40395", "title": "Kay 's scan", "surveycode": "100138", "questioncount": "2", "startdate": "2010-09-30 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44263", "title": "kay survey number test", "surveycode": "9735", "questioncount": "0", "startdate": "2012-08-06 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "39245", "title": "Kevin's Test", "surveycode": "100076", "questioncount": "12", "startdate": "2010-07-01 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "null", "activationtype": "null"},{"_id": "40637", "title": "Large Result Code", "surveycode": "100140", "questioncount": "4", "startdate": "2010-11-22 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "42126", "title": "large survey", "surveycode": "100147", "questioncount": "75", "startdate": "2011-07-26 12:00:00.000", "enddate": "2013-12-31 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "0", "activationtype": "null"},{"_id": "43792", "title": "Location/Prod/Picture Test", "surveycode": "200004", "questioncount": "3", "startdate": "2012-05-18 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "0", "activationtype": "null"},{"_id": "43378", "title": "Lots More Questions", "surveycode": "100163", "questioncount": "30", "startdate": "2012-03-30 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "37908", "title": "Market Research", "surveycode": "100005", "questioncount": "12", "startdate": "2009-06-01 12:00:00.000", "enddate": "2015-06-01 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "null", "activationtype": "null"},{"_id": "44401", "title": "Masco Skips test 2", "surveycode": "200023", "questioncount": "0", "startdate": "2012-09-04 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "40817", "title": "MASCO test 40060", "surveycode": "7251", "questioncount": "2", "startdate": "2011-01-06 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44400", "title": "masco test skips", "surveycode": "200016", "questioncount": "0", "startdate": "2012-09-04 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "39826", "title": "mult choice test survey", "surveycode": "100094", "questioncount": "9", "startdate": "2010-06-24 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "40888", "title": "mult choice test survey 2", "surveycode": "7254", "questioncount": "4", "startdate": "2011-01-14 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "37909", "title": "New Product Training", "surveycode": "100006", "questioncount": "8", "startdate": "2009-06-01 12:00:00.000", "enddate": "2015-06-01 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "null", "activationtype": "null"},{"_id": "39825", "title": "Nother one", "surveycode": "100093", "questioncount": "4", "startdate": "2010-06-24 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43822", "title": "Over 200 Questions", "surveycode": "200005", "questioncount": "215", "startdate": "2012-05-23 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44671", "title": "Preferences", "surveycode": "200029", "questioncount": "0", "startdate": "2013-02-11 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "6"},{"_id": "43181", "title": "prod/loc test", "surveycode": "100158", "questioncount": "3", "startdate": "2012-02-27 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43988", "title": "Product Survey with Photos", "surveycode": "200007", "questioncount": "5", "startdate": "2012-06-27 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "41851", "title": "Q types test", "surveycode": "7264", "questioncount": "4", "startdate": "2011-06-03 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43156", "title": "Question Skipping Test", "surveycode": "100157", "questioncount": "20", "startdate": "2012-02-20 12:00:00.000", "enddate": "2099-08-05 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44084", "title": "Question Type Testing", "surveycode": "200009", "questioncount": "0", "startdate": "2012-07-16 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "43770", "title": "Received at CRC from Field", "surveycode": "200001", "questioncount": "0", "startdate": "2012-05-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43772", "title": "Received at CRC from Intermec", "surveycode": "200003", "questioncount": "0", "startdate": "2012-05-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "39838", "title": "Sample Survey", "surveycode": "100096", "questioncount": "4", "startdate": "2010-06-25 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43673", "title": "Sample Survey - No Date Questions", "surveycode": "100165", "questioncount": "14", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43680", "title": "Sample Survey - No Date Questions #10", "surveycode": "100172", "questioncount": "15", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43674", "title": "Sample Survey - No Date Questions #2", "surveycode": "100166", "questioncount": "14", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43675", "title": "Sample Survey - No Date Questions #3", "surveycode": "100167", "questioncount": "14", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43676", "title": "Sample Survey - No Date Questions #4", "surveycode": "100168", "questioncount": "14", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43681", "title": "Sample Survey - No Date Questions #5", "surveycode": "100174", "questioncount": "14", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43677", "title": "Sample Survey - No Date Questions #6", "surveycode": "100169", "questioncount": "14", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43678", "title": "Sample Survey - No Date Questions #7", "surveycode": "100170", "questioncount": "15", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43683", "title": "Sample Survey - No Date Questions #8", "surveycode": "100173", "questioncount": "14", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43679", "title": "Sample Survey - No Date Questions #9", "surveycode": "100171", "questioncount": "15", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43769", "title": "Sent to Field from CRC", "surveycode": "200000", "questioncount": "0", "startdate": "2012-05-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43771", "title": "Sent to Intermec from CRC", "surveycode": "200002", "questioncount": "0", "startdate": "2012-05-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "42127", "title": "small test", "surveycode": "100148", "questioncount": "75", "startdate": "2011-07-26 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "18803", "title": "Stevens Final test Survey", "surveycode": "1992", "questioncount": "5", "startdate": "2007-03-01 12:00:00.000", "enddate": "2017-03-01 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "1", "activationtype": "null"},{"_id": "39614", "title": "Survey 1 - Home Depot Books/Mags - 05/03/2010", "surveycode": "1", "questioncount": "28", "startdate": "2010-05-03 12:00:00.000", "enddate": "2015-05-03 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "39620", "title": "Survey 2005 - Manager Only - Picture Survey", "surveycode": "2005", "questioncount": "2", "startdate": "2005-02-01 12:00:00.000", "enddate": "2015-05-01 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "null", "activationtype": "null"},{"_id": "39615", "title": "Survey 3 - Home Depot Book/Mag Manager Only Survey", "surveycode": "3", "questioncount": "14", "startdate": "2009-03-01 12:00:00.000", "enddate": "2015-03-01 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "null", "activationtype": "null"},{"_id": "39621", "title": "Survey 599 - TNG Reset Log In Survey", "surveycode": "599", "questioncount": "5", "startdate": "2009-08-20 12:00:00.000", "enddate": "2020-08-20 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "null", "activationtype": "null"},{"_id": "39623", "title": "Survey 7250 - Store Racking Survey", "surveycode": "7250", "questioncount": "4", "startdate": "2010-05-11 12:00:00.000", "enddate": "2015-05-11 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "null", "activationtype": "null"},{"_id": "39622", "title": "Survey 799 - TNG Manager's Only Survey", "surveycode": "799", "questioncount": "4", "startdate": "2009-08-20 12:00:00.000", "enddate": "2020-08-20 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "null", "activationtype": "null"},{"_id": "38630", "title": "Survey Switch Test 1", "surveycode": "100064", "questioncount": "5", "startdate": "2009-10-20 12:00:00.000", "enddate": "2020-10-20 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "38631", "title": "Survey Switch Test 2", "surveycode": "100063", "questioncount": "7", "startdate": "2009-10-20 12:00:00.000", "enddate": "2020-10-20 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "null", "activationtype": "null"},{"_id": "44645", "title": "surveygrid sample questions", "surveycode": "200027", "questioncount": "5", "startdate": "2013-01-16 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "6"},{"_id": "40879", "title": "test", "surveycode": "7252", "questioncount": "4", "startdate": "2010-11-22 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43223", "title": "test store/emp group", "surveycode": "100161", "questioncount": "2", "startdate": "2012-03-06 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43774", "title": "Testing Asset Reporting", "surveycode": "2345", "questioncount": "1", "startdate": "2012-05-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44527", "title": "text test", "surveycode": "200022", "questioncount": "0", "startdate": "2012-09-28 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43865", "title": "Treena Completion Test", "surveycode": "200006", "questioncount": "2", "startdate": "2012-05-31 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "40049", "title": "Upload Document Survey 1", "surveycode": "100127", "questioncount": "1", "startdate": "2010-08-02 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "4111", "title": "Your Sample Survey 42", "surveycode": "42", "questioncount": "15", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"}];
					var surveys = [{"_id": "41515", "title": "!Survey", "surveycode": "7258", "questioncount": "12", "startdate": "2011-05-02 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "41159", "title": "!Skip to my Lou!", "surveycode": "7257", "questioncount": "5", "startdate": "2011-03-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "40021", "title": "!test3542", "surveycode": "100123", "questioncount": "3", "startdate": "2010-07-29 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "41692", "title": "05/27/2011 Survey", "surveycode": "7261", "questioncount": "1", "startdate": "2011-05-27 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "40252", "title": "1.0.3.4 test", "surveycode": "100133", "questioncount": "6", "startdate": "2010-09-09 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "44541", "title": "10-2-12 upgrade test", "surveycode": "200024", "questioncount": "0", "startdate": "2012-10-02 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44539", "title": "1002 test", "surveycode": "200017", "questioncount": "0", "startdate": "2012-10-02 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "3"},{"_id": "41592", "title": "42637", "surveycode": "7259", "questioncount": "1", "startdate": "2011-05-10 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "41948", "title": "43381 test", "surveycode": "7265", "questioncount": "1", "startdate": "2011-06-27 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "42206", "title": "44140 Testing", "surveycode": "100152", "questioncount": "4", "startdate": "2011-08-04 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "41738", "title": "6/1/2011 test", "surveycode": "7263", "questioncount": "12", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43738", "title": "A New Product Survey", "surveycode": "100175", "questioncount": "4", "startdate": "2012-05-14 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "1", "activationtype": "null"},{"_id": "44283", "title": "AAATest For Photos", "surveycode": "200011", "questioncount": "0", "startdate": "2012-08-09 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44102", "title": "All Question Type Testing", "surveycode": "200010", "questioncount": "0", "startdate": "2012-07-19 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "43754", "title": "Aloha Sample 1", "surveycode": "100177", "questioncount": "18", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "43755", "title": "Aloha Sample 3", "surveycode": "100178", "questioncount": "20", "startdate": "2012-02-20 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43756", "title": "Aloha Sample 4", "surveycode": "100179", "questioncount": "14", "startdate": "2012-05-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "41052", "title": "Android Photo questions", "surveycode": "7255", "questioncount": "3", "startdate": "2011-02-20 12:00:00.000", "enddate": "2015-02-20 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "null", "activationtype": "null"},{"_id": "41315", "title": "Android Survey #1", "surveycode": "2227", "questioncount": "3", "startdate": "2011-03-29 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "41316", "title": "Android Survey #2", "surveycode": "2228", "questioncount": "2", "startdate": "2011-03-30 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "41317", "title": "Android Survey #3", "surveycode": "2229", "questioncount": "2", "startdate": "2011-03-30 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "41318", "title": "Android Survey #4", "surveycode": "2230", "questioncount": "2", "startdate": "2011-03-30 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44284", "title": "Angie Survey Test 1", "surveycode": "200012", "questioncount": "0", "startdate": "2012-08-09 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44288", "title": "Another Picture Test", "surveycode": "200013", "questioncount": "0", "startdate": "2012-08-09 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "39548", "title": "Chad Test Survey", "surveycode": "100081", "questioncount": "13", "startdate": "2009-01-01 12:00:00.000", "enddate": "2099-01-01 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "43758", "title": "Completion Test Survey", "surveycode": "100180", "questioncount": "2", "startdate": "2012-05-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43253", "title": "copy of (small) test", "surveycode": "100162", "questioncount": "75", "startdate": "2011-07-26 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "42164", "title": "Copy of Books and Mags for question savin", "surveycode": "100149", "questioncount": "14", "startdate": "2011-08-01 12:00:00.000", "enddate": "2015-03-01 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "40037", "title": "Copy of Chad Test Survey", "surveycode": "100126", "questioncount": "10", "startdate": "2009-01-01 12:00:00.000", "enddate": "2099-01-01 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "40880", "title": "Copy Survey Results Test", "surveycode": "7253", "questioncount": "2", "startdate": "2011-01-13 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "40025", "title": "copytest", "surveycode": "100125", "questioncount": "1", "startdate": "2010-07-29 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "1", "activationtype": "null"},{"_id": "43200", "title": "Dashboard Testing Survey", "surveycode": "100160", "questioncount": "3", "startdate": "2011-03-05 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "0", "activationtype": "null"},{"_id": "44064", "title": "Dog Food Brands", "surveycode": "200008", "questioncount": "0", "startdate": "2012-07-12 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43196", "title": "Exit Survey Question Testing", "surveycode": "100159", "questioncount": "19", "startdate": "2012-02-20 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "0", "activationtype": "null"},{"_id": "15767", "title": "Handheld Sample Survey", "surveycode": "43", "questioncount": "6", "startdate": "2006-06-01 12:00:00.000", "enddate": "2030-06-01 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "null", "activationtype": "null"},{"_id": "43773", "title": "Initial Inventory", "surveycode": "199999", "questioncount": "23", "startdate": "2012-05-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43090", "title": "Intelligent Question Testing", "surveycode": "100156", "questioncount": "7", "startdate": "2012-02-07 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "0", "activationtype": "null"},{"_id": "43627", "title": "iPad Attachment Testing", "surveycode": "100164", "questioncount": "5", "startdate": "2012-05-02 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "0", "activationtype": "null"},{"_id": "41691", "title": "Jake's Sample Survey", "surveycode": "7260", "questioncount": "18", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "41722", "title": "Jake's Sample Survey #2", "surveycode": "7262", "questioncount": "15", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "40395", "title": "Kay 's scan", "surveycode": "100138", "questioncount": "2", "startdate": "2010-09-30 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44263", "title": "kay survey number test", "surveycode": "9735", "questioncount": "0", "startdate": "2012-08-06 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "39245", "title": "Kevin's Test", "surveycode": "100076", "questioncount": "12", "startdate": "2010-07-01 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "null", "activationtype": "null"},{"_id": "40637", "title": "Large Result Code", "surveycode": "100140", "questioncount": "4", "startdate": "2010-11-22 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "42126", "title": "large survey", "surveycode": "100147", "questioncount": "75", "startdate": "2011-07-26 12:00:00.000", "enddate": "2013-12-31 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "0", "activationtype": "null"},{"_id": "43792", "title": "Location/Prod/Picture Test", "surveycode": "200004", "questioncount": "3", "startdate": "2012-05-18 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "0", "activationtype": "null"},{"_id": "43378", "title": "Lots More Questions", "surveycode": "100163", "questioncount": "30", "startdate": "2012-03-30 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "37908", "title": "Market Research", "surveycode": "100005", "questioncount": "12", "startdate": "2009-06-01 12:00:00.000", "enddate": "2015-06-01 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "null", "activationtype": "null"},{"_id": "44401", "title": "Masco Skips test 2", "surveycode": "200023", "questioncount": "0", "startdate": "2012-09-04 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "40817", "title": "MASCO test 40060", "surveycode": "7251", "questioncount": "2", "startdate": "2011-01-06 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44400", "title": "masco test skips", "surveycode": "200016", "questioncount": "0", "startdate": "2012-09-04 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "39826", "title": "mult choice test survey", "surveycode": "100094", "questioncount": "9", "startdate": "2010-06-24 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "40888", "title": "mult choice test survey 2", "surveycode": "7254", "questioncount": "4", "startdate": "2011-01-14 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "37909", "title": "New Product Training", "surveycode": "100006", "questioncount": "8", "startdate": "2009-06-01 12:00:00.000", "enddate": "2015-06-01 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "null", "activationtype": "null"},{"_id": "39825", "title": "Nother one", "surveycode": "100093", "questioncount": "4", "startdate": "2010-06-24 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43822", "title": "Over 200 Questions", "surveycode": "200005", "questioncount": "215", "startdate": "2012-05-23 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44671", "title": "Preferences", "surveycode": "200029", "questioncount": "0", "startdate": "2013-02-11 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "6"},{"_id": "43181", "title": "prod/loc test", "surveycode": "100158", "questioncount": "3", "startdate": "2012-02-27 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43988", "title": "Product Survey with Photos", "surveycode": "200007", "questioncount": "5", "startdate": "2012-06-27 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "41851", "title": "Q types test", "surveycode": "7264", "questioncount": "4", "startdate": "2011-06-03 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43156", "title": "Question Skipping Test", "surveycode": "100157", "questioncount": "20", "startdate": "2012-02-20 12:00:00.000", "enddate": "2099-08-05 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44084", "title": "Question Type Testing", "surveycode": "200009", "questioncount": "0", "startdate": "2012-07-16 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "43770", "title": "Received at CRC from Field", "surveycode": "200001", "questioncount": "0", "startdate": "2012-05-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43772", "title": "Received at CRC from Intermec", "surveycode": "200003", "questioncount": "0", "startdate": "2012-05-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "39838", "title": "Sample Survey", "surveycode": "100096", "questioncount": "4", "startdate": "2010-06-25 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43673", "title": "Sample Survey - No Date Questions", "surveycode": "100165", "questioncount": "14", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43680", "title": "Sample Survey - No Date Questions #10", "surveycode": "100172", "questioncount": "15", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43674", "title": "Sample Survey - No Date Questions #2", "surveycode": "100166", "questioncount": "14", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43675", "title": "Sample Survey - No Date Questions #3", "surveycode": "100167", "questioncount": "14", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43676", "title": "Sample Survey - No Date Questions #4", "surveycode": "100168", "questioncount": "14", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43681", "title": "Sample Survey - No Date Questions #5", "surveycode": "100174", "questioncount": "14", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43677", "title": "Sample Survey - No Date Questions #6", "surveycode": "100169", "questioncount": "14", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43678", "title": "Sample Survey - No Date Questions #7", "surveycode": "100170", "questioncount": "15", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43683", "title": "Sample Survey - No Date Questions #8", "surveycode": "100173", "questioncount": "14", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43679", "title": "Sample Survey - No Date Questions #9", "surveycode": "100171", "questioncount": "15", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43769", "title": "Sent to Field from CRC", "surveycode": "200000", "questioncount": "0", "startdate": "2012-05-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43771", "title": "Sent to Intermec from CRC", "surveycode": "200002", "questioncount": "0", "startdate": "2012-05-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "42127", "title": "small test", "surveycode": "100148", "questioncount": "75", "startdate": "2011-07-26 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "18803", "title": "Stevens Final test Survey", "surveycode": "1992", "questioncount": "5", "startdate": "2007-03-01 12:00:00.000", "enddate": "2017-03-01 12:00:00.000", "mandatory": "0", "skipable": "1", "canaudit": "1", "activationtype": "null"},{"_id": "39614", "title": "Survey 1 - Home Depot Books/Mags - 05/03/2010", "surveycode": "1", "questioncount": "28", "startdate": "2010-05-03 12:00:00.000", "enddate": "2015-05-03 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "39620", "title": "Survey 2005 - Manager Only - Picture Survey", "surveycode": "2005", "questioncount": "2", "startdate": "2005-02-01 12:00:00.000", "enddate": "2015-05-01 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "null", "activationtype": "null"},{"_id": "39615", "title": "Survey 3 - Home Depot Book/Mag Manager Only Survey", "surveycode": "3", "questioncount": "14", "startdate": "2009-03-01 12:00:00.000", "enddate": "2015-03-01 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "null", "activationtype": "null"},{"_id": "39621", "title": "Survey 599 - TNG Reset Log In Survey", "surveycode": "599", "questioncount": "5", "startdate": "2009-08-20 12:00:00.000", "enddate": "2020-08-20 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "null", "activationtype": "null"},{"_id": "39623", "title": "Survey 7250 - Store Racking Survey", "surveycode": "7250", "questioncount": "4", "startdate": "2010-05-11 12:00:00.000", "enddate": "2015-05-11 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "null", "activationtype": "null"},{"_id": "39622", "title": "Survey 799 - TNG Manager's Only Survey", "surveycode": "799", "questioncount": "4", "startdate": "2009-08-20 12:00:00.000", "enddate": "2020-08-20 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "null", "activationtype": "null"},{"_id": "38630", "title": "Survey Switch Test 1", "surveycode": "100064", "questioncount": "5", "startdate": "2009-10-20 12:00:00.000", "enddate": "2020-10-20 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "1", "activationtype": "null"},{"_id": "38631", "title": "Survey Switch Test 2", "surveycode": "100063", "questioncount": "7", "startdate": "2009-10-20 12:00:00.000", "enddate": "2020-10-20 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "null", "activationtype": "null"},{"_id": "44645", "title": "surveygrid sample questions", "surveycode": "200027", "questioncount": "5", "startdate": "2013-01-16 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "6"},{"_id": "40879", "title": "test", "surveycode": "7252", "questioncount": "4", "startdate": "2010-11-22 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43223", "title": "test store/emp group", "surveycode": "100161", "questioncount": "2", "startdate": "2012-03-06 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43774", "title": "Testing Asset Reporting", "surveycode": "2345", "questioncount": "1", "startdate": "2012-05-17 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "44527", "title": "text test", "surveycode": "200022", "questioncount": "0", "startdate": "2012-09-28 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "43865", "title": "Treena Completion Test", "surveycode": "200006", "questioncount": "2", "startdate": "2012-05-31 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "40049", "title": "Upload Document Survey 1", "surveycode": "100127", "questioncount": "1", "startdate": "2010-08-02 12:00:00.000", "enddate": "2099-12-31 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"},{"_id": "4111", "title": "Your Sample Survey 42", "surveycode": "42", "questioncount": "15", "startdate": "2002-07-18 12:00:00.000", "enddate": "2020-07-18 12:00:00.000", "mandatory": "0", "skipable": "0", "canaudit": "0", "activationtype": "null"}];
					for(var i = 0, len = surveys.length; i < len; i++){
						var item = surveys[i], fields = [], values = [];
						for(var field in item){
							fields = fields.concat([field]);
							values = values.concat(["'" + item[field] + "'"]);
						}
						var query = "INSERT INTO surveys (" + fields.join(",") + ") VALUES (" + values.join(",") + ")";
						this.executeReader(query, crcDB, function(t, r_or_e){});
					}
					//surveyanswersession:
					//[{"SessionID": "1", "PushedAnswerID": "-1", "StoreActivityID": "-1001", "loginid": "-1001", "LogoutID": "-1", "storeid": "1374143", "surveyid": "41159", "surveycode": "7257", "AnswerTime": "Fri Apr 26 17:46:50 EDT 2013", "ArrivalTime": "63983718", "LocationID": "0", "LocationSequence": "0", "ProductID": "0", "ScheduleID": "-1"}] 
					
					var query = "create table SurveyAnswerSession (SessionID integer not null primary key autoincrement, StoreActivityID int, PushedAnswerID text, loginid text,LogoutID text,storeid text, surveyid text, surveycode text,AnswerTime text, ArrivalTime text, LocationID int, LocationSequence int, ProductID int,ScheduleID int)"
					this.executeReader(query, crcDB, function(t, r_or_e){});
					var surveyanswersession = [{"SessionID": "1", "PushedAnswerID": "-1", "StoreActivityID": "-1001", "loginid": "-1001", "LogoutID": "-1", "storeid": "1374143", "surveyid": "41159", "surveycode": "7257", "AnswerTime": "Fri Apr 26 17:46:50 EDT 2013", "ArrivalTime": "63983718", "LocationID": "0", "LocationSequence": "0", "ProductID": "0", "ScheduleID": "-1"}];
					for(var i = 0, len = surveyanswersession.length; i < len; i++){
						var item = surveyanswersession[i], fields = [], values = [];
						for(var field in item){
							fields = fields.concat([field]);
							values = values.concat(["'" + item[field] + "'"]);
						}
						var query = "INSERT INTO surveyanswersession (" + fields.join(",") + ") VALUES (" + values.join(",") + ")";
						this.executeReader(query, crcDB, function(t, r_or_e){});
					}
					
					query = "SELECT s._id, s.title, sas.sessionid, sas.surveycode as Ans FROM surveys s left join surveyanswersession sas " 
							+  "ON s.surveycode = sas.surveycode"
							+ " ORDER BY s.title COLLATE NOCASE ASC";
					
					//var query = "SELECT * FROM SurveyAnswerSession";
					this.executeReader(query, crcDB, function(t, r_or_e){
						// var item = r_or_e.rows.item(1);
						// for(var fld in item){
							// console.log(fld + ": " + item[fld]);
						// }
						console.log(r_or_e);
						
					});
					
				}
			}
			
			//field = null returns false
			,"6d" : {
				"preTest" : function(){
				
					this.initDB();

					var query = "drop table if exists Product;";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "create table Product(ProductID int not null primary key, UPC text, ProductName text, ProductDescription text, InternalCode text);"
					this.executeReader(query, crcDB, function(t, r_or_e){});

					
					var me = this;

					var products = [
						'insert into Product(ProductID, UPC, ProductName, ProductDescription, InternalCode) values(17130,"016000338500","Betty Crocker Apple Streusel Muffin Mix","Apple Streusel Muffin Mix", null);'
					];
					
					for(var i = 0, len = products.length; i < len; i++){
						this.executeReader(products[i], crcDB, function(t, r_or_e){});
					}
					
				}
			   
			   ,"query" : "select * from product where InternalCode = null"
			   
			   ,"expectedData" : [
					{'ProductID' : 17130,  'UPC' : "016000338500", 'ProductName' : "Betty Crocker Apple Streusel Muffin Mix", 'ProductDescription' : "Apple Streusel Muffin Mix", 'InternalCode' :  null}
				]
				
				,"evaluateResult" : function(t, r_or_e, testParams){

					return (
							 r_or_e.rows.length == 0
						//&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData, false)
					);

			    }
			}
			
			//escaping of quotes is correct
			,"6e" : {
				"preTest" : function(){
				
					this.initDB();

					var query = "drop table if exists Product;";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "create table Product(ProductID int not null primary key, UPC text, ProductName text, ProductDescription text, InternalCode text);"
					this.executeReader(query, crcDB, function(t, r_or_e){});

					
					var me = this;

					var products = [
						'insert into Product(ProductID, UPC, ProductName, ProductDescription, InternalCode) values(17130,"016000338500","""Test""","Apple Streusel Muffin Mix", null);'
                       ,'insert into Product(ProductID, UPC, ProductName, ProductDescription, InternalCode) values(17131,"016000338500","""Test","Apple Streusel Muffin Mix", null);'
					   ,'insert into Product(ProductID, UPC, ProductName, ProductDescription, InternalCode) values(17132,"016000338500","Test""","Apple Streusel Muffin Mix", null);'
					];
					
					for(var i = 0, len = products.length; i < len; i++){
						this.executeReader(products[i], crcDB, function(t, r_or_e){});
					}
					
				}
			   
			   ,"query" : "select * from product"
			   
			   ,"expectedData" : [
					{'ProductID' : 17130,  'UPC' : "016000338500", 'ProductName' : '"Test"', 'ProductDescription' : "Apple Streusel Muffin Mix", 'InternalCode' :  null}
				   ,{'ProductID' : 17131,  'UPC' : "016000338500", 'ProductName' : '"Test', 'ProductDescription' : "Apple Streusel Muffin Mix", 'InternalCode' :  null}
				   ,{'ProductID' : 17132,  'UPC' : "016000338500", 'ProductName' : 'Test"', 'ProductDescription' : "Apple Streusel Muffin Mix", 'InternalCode' :  null}
				]
				
				,"evaluateResult" : function(t, r_or_e, testParams){

					return (
						HPI.isEqual(this.srData(r_or_e), testParams.expectedData, false)
					);

			    }
			}
			
			//,"testOnly" : "6d"
			//performance improvment test
			,"6f" : {
				
				"_testFn" : function(){
				
					this.initDB();
					var me = this;
					/*
					var query = "DROP TABLE IF EXISTS tbl1";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					query = "create table tbl1(a int, b int, c int)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					for(var i = 1, len = 1027; i <= len; i++){
						query = "Insert Into tbl1 values(?,?,?)".replace(/\?/g, i);
						this.executeReader(query, crcDB, function(t, r_or_e){});					
					}
					
					query = "select * from tbl1";
					this.executeReader(query, crcDB, function(t, r_or_e){//console.log(r_or_e);
					});
					
					var query = "DROP TABLE IF EXISTS tbl2";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					query = "create table tbl2(d int, e int, f int)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					for(var i = 1, len = 887; i <= len; i++){
						query = "Insert Into tbl2 values(?,?,?)".replace(/\?/g, i);
						this.executeReader(query, crcDB, function(t, r_or_e){});					
					}
			
					query = "select * from tbl1";
					this.executeReader(query, crcDB, function(t, r_or_e){//console.log(r_or_e);
					});
					*/
					
					//query = "select * from tbl1 inner join tbl2 on a = e where a = 1 and b = 1 and e = 1";
					query = "select tbl2.*, tbl1.a as _id from tbl1 inner join tbl2  on tbl1.a == tbl2.e where tbl1.a = 1 and tbl1.b = 1 order by tbl2.d";
					this.executeReader(query, crcDB, function(t, r_or_e){//console.log(r_or_e);
					});

				}
				
			}
			
			//test if using alias.* works with order by
			//,"testOnly" : "6g"
			,"6g" : {
			
				"testFn" : function(){
				
					this.initDB();
					var queries = [
						'drop table if exists stores'
						,'create table stores (_id integer not null primary key autoincrement, chainid int, chaincode text, storename text, storenumber text, chainstorenumber text, address1 text, address2 text, city text, state text, zip text, lat text, long text, phone text, TerritoryID int, Notes text, NotesEx text, QuestionLabels text);'
						,'insert into stores( _id, chainid, chaincode, storename, storenumber, chainstorenumber, address1, ' +
						 ' address2, city, state, zip, lat, long, phone, TerritoryID, Notes, NotesEx, QuestionLabels) ' +
						 ' values  ("25868","9419","50","Winn Dixie #3029","50","","3503 Piedmont RD","","Atlanta","GA","30305","34.2098","-84.1367","4045555555","116","","","");'
					];
					
					for(var i = 0, len = queries.length; i < len; i++){						
						this.executeReader(queries[i], crcDB, function(t, r_or_e){});					
					}
					
					
					queries = [
						 'drop table if exists vhistory;'
						,'create table vhistory (_id integer not null primary key autoincrement, vhchaincode text, vhstorenumber text, visitid text, confirmationnumber text, idnumber text, employeename text, logindate text, logoutdate text, empauditavg text, emplastaudit text, storeauditavg text, storelastaudit text, loginID );'
						,'insert into vhistory(_id, vhchaincode, vhstorenumber, visitid, confirmationnumber, idnumber, employeename ' +
							', logindate, logoutdate, empauditavg, emplastaudit, storeauditavg, storelastaudit, loginID) ' +
							 ' values ("26251250","50","50","26251250","26270674","1236","Android User #2","2012-10-06 06:42:00.000","2012-10-06 06:43:00.000","0","","0","","26252549")'
					];

					for(var i = 0, len = queries.length; i < len; i++){						
						this.executeReader(queries[i], crcDB, function(t, r_or_e){});
					}
					
					query = 'select stores.* from stores where ChainCode = 50 ' +
						'and StoreNumber in ( ' +
							'select vhStoreNumber from vhistory where vhChainCode = 50 ' +
						') ' +
						'order by cast(StoreNumber as integer) asc'
						
					this.executeReader(query, crcDB, function(t, r_or_e){
						assertTrue(r_or_e.rows.length == 1);
					});
				
				}
			
			}
			
			//,"testOnly"  : "6h"
			//test if join with ambiguous fields, and using alias.* in project, and field reference to ambi. field (in where, join cond. order by, etc.) causes error
			,"6h" : {
			
				"testFn" : function(){
				
					this.initDB();
					var queries = [
						'drop table if exists tbl1'
						,'create table tbl1 (a int, b int, c int);'
						,'insert into tbl1 values(1, 1, 1)'
					];
					
					for(var i = 0, len = queries.length; i < len; i++){						
						this.executeReader(queries[i], crcDB, function(t, r_or_e){});					
					}
					
					var queries = [
						 'drop table if exists tbl2'
						,'create table tbl2 (a int, b int, c int);'
						,'insert into tbl2 values(1, 1, 1)'
					];

					for(var i = 0, len = queries.length; i < len; i++){			
						this.executeReader(queries[i], crcDB, function(t, r_or_e){});
					}
					
					var queries = [
						 'select tbl1.*, tbl2.* from tbl1 inner join tbl2 on tbl1.a = tbl2.a where a = 1'
						,'select tbl1.*, tbl2.* from tbl1 inner join tbl2 on tbl1.a = tbl2.a order by cast(a as int)'
						,'select tbl1.*, tbl2.* from tbl1 inner join tbl2 on tbl1.a = tbl2.a order by a'
						,'select tbl1.*, tbl2.* from tbl1 inner join tbl2 on a = a'
					];

					for(var i = 0, len = queries.length; i < len; i++){						
						 this.executeReader(queries[i], crcDB, function(t, r_or_e){
							assertTrue(
										r_or_e instanceof HPI.SQLError
								&& 	r_or_e.message == "could not prepare statement (1 ambiguous column name:a)"
								&&	r_or_e.code == HPI.SQLError.SYNTAX_ERR
							);
						});
					}					
				
				}
			}
			
			//,"testOnly" : "12"
			,"12" : {
			
				"preTest" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS Contacts";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "DROP TABLE IF EXISTS ContactStore";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					
					var me = this;
					
					query = "create table Contacts(ContactID int, FirstName text, LastName text)";	
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						query = 'INSERT INTO Contacts (ContactID, FirstName, LastName) VALUES ' +
									'(1, "fn1", "ln1")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO Contacts (ContactID, FirstName, LastName) VALUES ' +
									'(2, "fn2", "ln2")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
						query = 'INSERT INTO Contacts (ContactID, FirstName, LastName) VALUES ' +
									'(3, "fn3", "ln3")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
						query = 'INSERT INTO Contacts (ContactID, FirstName, LastName) VALUES ' +
									'(4, "fn4", "ln4")';
						
						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
						query = 'INSERT INTO Contacts (ContactID, FirstName, LastName) VALUES ' +
									'(5, "fn5", "ln5")';
									
						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
					});
					
					
					query = "create table ContactStore(ContactID int, StoreID int)";
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						query = 'INSERT INTO ContactStore (ContactID, StoreID) VALUES ' +
									'(4, 1)';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO ContactStore (ContactID, StoreID) VALUES ' +
									'(5, 1)';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
						query = 'INSERT INTO ContactStore (ContactID, StoreID) VALUES ' +
									'(6, 2)';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});						
						
					});
					
				}
				
			   ,"query" : "select FirstName,LastName from Contacts where ContactID = 1 or ContactID In(Select ContactID From ContactStore Where StoreID = 1)"
			   
			   ,"expectedData" : [
					{"FirstName" : "fn1", "LastName" : "ln1"}
				   ,{"FirstName" : "fn4", "LastName" : "ln4"}
				   ,{"FirstName" : "fn5", "LastName" : "ln5"}
				]
				
			   ,"evaluateResult" : function(t, r_or_e, testParams){//console.log(r_or_e);

					return (
							 r_or_e.rows.length == 3
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData, false)
					);
			   
			    }
				
			}			
			
			,"12a" : {
			
			
				"preTest" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS appstatus";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table appstatus(name text, value text)";
					
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						query = 'INSERT INTO appstatus (name, value) VALUES ' +
									'("CHAIN_NUMBER", "v1")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
						query = 'INSERT INTO appstatus (name, value) VALUES ' +
									'("NOT_TO_BE_INCLUDED", "v3")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO appstatus (name, value) VALUES ' +
									'("STORE_ID", "v2")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});

					});					
					
				}
				
			   ,"query" : "select * from appstatus where Name in ('CHAIN_NUMBER','STORE_ID')"
			
			   ,"expectedData" : [
					{"name" : "CHAIN_NUMBER", "value" : "v1"}
				   ,{"name" : "STORE_ID", "value" : "v2"}
				]
				
			   ,"evaluateResult" : function(t, r_or_e, testParams){//console.log(r_or_e);

					return (
							 r_or_e.rows.length == 2
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData, false)
					);

                }
			
			}			
			
			//,"testOnly" : "12b"

			,"12b" : {
			
				"testFn" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS preferences";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table preferences(prefname text, intvalue int)";
					
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "Insert Into preferences (prefname, intvalue) values('a1', 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					query = "Insert Into preferences (prefname, intvalue) values('a2', 2)";
					this.executeReader(query, crcDB, function(t, r_or_e){console.log(r_or_e);});
					
					query = "Insert Into preferences (prefname, intvalue) values('a3', 3)";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					query = "Insert Into preferences (prefname, intvalue) values('3a', 4)";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					query = "Insert Into preferences (prefname, intvalue) values('3b', 5)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "select prefname, intvalue from preferences where prefname like 'a%'";
					this.executeReader(query, crcDB, function(t, r_or_e){
						
						console.log(r_or_e);
						
					});
					
					
				}
				
			}
			
			,"7" : {
				"preTest" : function(){
					
					
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS SurveyAuditAnswerSession";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table SurveyAuditAnswerSession(SessionId int, Pushedanswerid text)";
					
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						query = 'INSERT INTO SurveyAuditAnswerSession (SessionId, Pushedanswerid) VALUES ' +
									'(1, "ANS1")';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO SurveyAuditAnswerSession (SessionId, Pushedanswerid) VALUES ' +
									'(2, "ANS2")';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO SurveyAuditAnswerSession (SessionId, Pushedanswerid) VALUES ' +
									'(3, "ANS3")';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO SurveyAuditAnswerSession (SessionId, Pushedanswerid) VALUES ' +
									'(4, "ANS4")';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});

					});					
					
				}
				
			   ,"query" : "Select Max(SessionId) as SessionId from SurveyAuditAnswerSession"
			   
			   ,"expectedData" : [
					{"SessionId" : 4}
			   ]
			   ,"evaluateResult" : function(t, r_or_e, testParams){
			   
					return (
							 r_or_e.rows.length == 1
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData, false)
					);
			   
			   }

			}
			
			//,"testOnly" : "10"
			,"10" : {
				"preTest" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS SurveyPicImages";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table SurveyPicImages(_id int primary key, AnswerID int)";
					
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						query = 'INSERT INTO SurveyPicImages (_id, AnswerID) VALUES ' +
									'(1, 1)';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO SurveyPicImages (_id, AnswerID) VALUES ' +
									'(2, 2)';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO SurveyPicImages (_id, AnswerID) VALUES ' +
									'(3, 3)';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO SurveyPicImages (_id, AnswerID) VALUES ' +
									'(4, 4)';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});						
					});
					
				}
				,"query" : "SELECT COUNT(*) AS Count From SurveyPicImages sp"
				//,"query" : "SELECT COUNT(*) AS Count, COUNT(*), _id, AnswerID, 1+1, 1+1 as 'a', 1+1 as b, sp._id as sp_id, sp.AnswerID as 'sp_answerid' From SurveyPicImages sp"
				//,"query" : "SELECT _id, sp._id as sp_id From SurveyPicImages sp"
			    ,"expectedData" : [{"Count" : 4}]
				,"evaluateResult" : function(t, r_or_e, testParams){
					//console.log(r_or_e);
					return (
							 r_or_e.rows.length == 1
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData, false)
					);
			   
			   }
			   
			 }
			 
			,"19" : {
				
				"query" : "Select (Min(ContactID)) as ContactID From Contacts "
			    ,"expectedData" : [
					{"ContactID" : 1}
				]
			   ,"evaluateResult" : function(t, r_or_e, testParams){

					return (
							 r_or_e.rows.length == 1
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData, false)
					);
			   
			    }
				
			}	

			
			,"22" : {
			
				"preTest" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS EmployeeVehicle";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table EmployeeVehicle(Vehicleid int primary key, Vehiclename int, Active int)";
					
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						query = 'INSERT INTO EmployeeVehicle (Vehicleid, Vehiclename, Active) VALUES ' +
									'(1, "V1", 1)';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO EmployeeVehicle (Vehicleid, Vehiclename, Active) VALUES ' +
									'(2, "V2", 0)';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO EmployeeVehicle (Vehicleid, Vehiclename, Active) VALUES ' +
									'(3, "V3", 1)';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO EmployeeVehicle (Vehicleid, Vehiclename, Active) VALUES ' +
									'(4, "V4", 0)';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
					});
					
				}
				
			   ,"query" : "Select (Max(VehicleID) + 1) as VehicleID From EmployeeVehicle"
			   
			   ,"expectedData" : [{"VehicleID" : 5}]
			   
			   ,"evaluateResult" : function(t, r_or_e, testParams){

					return (
							 r_or_e.rows.length == 1
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData, false)
					);
			   
			   }
			
			}	
			
			//todo: order by must support cases in which the ordered by clause mentions a field not in the specified field list
			
			,"23" : {
				"query" : "select count(*) as Count from EmployeeVehicle where Active=1 ORDER BY Vehiclename"
			   ,"expectedData" : [{"Count" : 2}]
			   ,"evaluateResult" : function(t, r_or_e, testParams){
					//console.log(r_or_e);
					return (
							 r_or_e.rows.length == 1
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData, false)
					);
			   
			   }
			}
		
			//,"testOnly" : "8"
			,"8" : {
			
				"preTest" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS Choices";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table Choices(" +
					"_id int primary key, ParentSurveyCode text, Qnumber int, Sequence int, " +
					"Value int, Displaytext text, Skipto int)";
					
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						query = 'INSERT INTO Choices (_id, ParentSurveyCode, Qnumber, Sequence, Value, Displaytext, Skipto) VALUES ' +
									'(1, 1, 1, 1, 1, "TEXT1", 1)';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO Choices (_id, ParentSurveyCode, Qnumber, Sequence, Value, Displaytext, Skipto) VALUES ' +
									'(2, 1, 1, 2, 2, "TEXT2", 2)';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
						query = 'INSERT INTO Choices (_id, ParentSurveyCode, Qnumber, Sequence, Value, Displaytext, Skipto) VALUES ' +
									'(3, 1, 1, 3, 3, "TEXT3", 3)';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO Choices (_id, ParentSurveyCode, Qnumber, Sequence, Value, Displaytext, Skipto) VALUES ' +
									'(4, 1, 1, 4, 4, "TEXT4", 4)';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						
					});					
					
				}
				
			   ,"query" : "Select skipto, " +
			   "(select Max(skipto) from choices where parentsurveycode = 1 And qnumber = 1) As MaxSkipTo, " + 
			   "(select Min(skipto) from choices where parentsurveycode = 1 And qnumber = 1) As MinSkipTo " +
			   "from choices where parentsurveycode = 1 And qnumber = 1 and value =1"
			   
			   //,"query" : "select Max(skipto) from choices where parentsurveycode = 1 And qnumber = 1"
			   ,"expectedData" : [
					{"skipto" : 1, "MaxSkipTo" : 4, "MinSkipTo" : 1}
				]
			   
			   ,"evaluateResult" : function(t, r_or_e, testParams){
					//console.log(r_or_e);
					return (
							 r_or_e.rows.length == 1
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData, false)
					);
			   
			   } 
			
			}		

			//,"testOnly" : ["21"]
			,"21" : {
				"preTest" : function(){
				
					//SurveyAnswerSession
					//SurveyProduct
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS SurveyProduct";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					var query = "DROP TABLE IF EXISTS SurveyAnswerSession";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table SurveyProduct(" +
								"Storeid int, Surveyid int, Productid int, Sequence int)";
					
					this.executeReader(query, crcDB, function(t, r_or_e){
						
						query = 'INSERT INTO SurveyProduct (Storeid, Surveyid, Productid, Sequence) VALUES ' +
									'(1, 1, 1, 1)';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO SurveyProduct (Storeid, Surveyid, Productid, Sequence) VALUES ' +
									'(2, 2, 2, 2)';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
					});

					query = "create table SurveyAnswerSession(" +
								"Sessionid int, PushedanswerID int, ProductId int, Locationid int, Surveyid int)";
					
					this.executeReader(query, crcDB, function(t, r_or_e){

						query = 'INSERT INTO SurveyAnswerSession (Sessionid, PushedanswerID, ProductId, Surveyid, Locationid) VALUES ' +
									'(1, 1, 1, 1, 1)';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO SurveyAnswerSession (Sessionid, PushedanswerID, ProductId, Surveyid, Locationid) VALUES ' +
									'(2, 2, 2, 2, 2)';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO SurveyAnswerSession (Sessionid, PushedanswerID, ProductId, Surveyid, Locationid) VALUES ' +
									'(3, 3, 3, 3, 3)';
						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
					});

				}
				
			   ,"query" : "select distinct (" +
								"Select '>>' from SurveyAnswerSession " +
								"Where ProductID=sp.ProductID And LocationID=  1 And surveyid = sp.SurveyID" +
							  ") As Ans," +
							  "sp.ProductID, sp.Sequence from " +
							  "SurveyProduct sp where surveyid = 1"
			   
			   ,"expectedData" : [
					{"Ans" : '>>', "ProductID" : 1, "Sequence" : 1}
				]
			   
			   ,"evaluateResult" : function(t, r_or_e, testParams){
					
					return (
							 r_or_e.rows.length == 1
						&& HPI.isEqual(this.srData(r_or_e), testParams.expectedData, false)
					);
			   
			   }
			   
			}

			//,"testOnly" : "21a"
			
			//retest distinct
			,"21a" : {
			
				"testFn" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS Product";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table Product(field1 text, field2 text)";
					
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "Insert Into Product (field1, field2) values('1', null)";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					query = "Insert Into Product (field1, field2) values('1', null)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "SELECT distinct * FROM Product;";
					this.executeReader(query, crcDB, function(t, r_or_e){
						
						assertTrue(
									r_or_e.rows.length == 1
							&&	r_or_e.rows.item(0).field1 == '1'
							&&	r_or_e.rows.item(0).field2 == null
						);
						
					});
				
				}
				
			}
			
			//,"testOnly" : "21b"
			
			//sorting test
			,"21b" : {
			
				"testFn" : function(){
						

					this.initDB();
					
					var query = "DROP TABLE IF EXISTS surveys";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table surveys(field1 text)";					
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var titles = [
						
						' Make Like Survey'
						,'AngieBugTest'
						,'aa_survey replica'
						,'for QuestionAnswer'
						,'KArl 976 Test'
						,'New MC test'
						
						
						,'New nomrla survey'
						
						,'PrivateProxy'
						,'Survey 13 - Hobby Lobby Book Order Survey'
						,'Survey 180 - Home Depot Candy Survey'
						,'Survey 182 - Self Checkout Survey'
						,'Survey 2005 - HD Candy Picture Survey'
						,'Survey 2750 - Merchandiser Picture Test Survey'
						,'Survey 33 - Hobby Lobby Service Survey'
						,'Survey 619 - Home Depot Mainline Audit Survey'
						,'Survey 62 - Fry\'s Electronics Survey'
						,'Survey 66 - Cabelas Service Survey'
						,'Survey 67 - Cabelas Media Center Survey'
						,'Survey 73 - Hobby Lobby Reset Survey'
						,'Trialssss'
						
						,'it will rain'
						
						,'karl follow up survey'
						,'karl sequence test'
						,'king survey'
						,'test123232'
						,'this is for unit testing all the Question Creation'
						
					];
					
					for(var i = 0, len = titles.length; i < len; i++){
						query = "insert into surveys(field1) VALUES ('" + titles[i] + "')";					
						this.executeReader(query, crcDB, function(t, r_or_e){});
					}
					
					query = "SELECT * FROM surveys ORDER BY field1 COLLATE NOCASE ASC;";
					this.executeReader(query, crcDB, function(t, r_or_e){
						
						//console.log(r_or_e);
						
					});
				}
			}
			
			,"99" : {
				"query" : "select distinct (Select '>>' from SurveyAnswerSession Where ProductID=sp.ProductID And LocationID=1 And surveyid = sp.SurveyID And surveyid =1)As Ans, sp.ProductID, p.ProductName, sas.SessionID, sas.LocationID, sp.Sequence from SurveyProduct sp"
			   ,"data" : []
			}

		    ,"26" : {
				"query" : "select Count(*) as LocationCount from SurveyLocation where StoreID=1 and SurveyID =1"
			   ,"data" : []			
			}
			
			,"24" : {
				"query" : "Select stores._id,stores.storenumber, stores.storename,Chains.chaincode,Chains.chainname From Stores Inner Join Chains On Stores.chainid = Chains._id where Stores._id= 1"
			   ,"data" : []
			}

			,"25" : {
				"query" : "select (Select '>>' from surveyanswersession Where surveycode=s.surveycode And StoreID = 1)As Ans, s.title,s.surveycode from surveys s inner join surveystores st "
                    + "on s.surveycode=st.sssurveycode where "
                    + " st.sschainnumber= 1 and st.ssstorenumber=1"
                    + " order by s.title"
			   ,"data" : []
			}
			
			
			,"9" : {
				"query" : "select choices.*,questions._id as surveyQId from questions Inner Join choices on questions.parentsurveycode == choices.parentsurveycode And questions.qnumber == choices.qnumber Where questions.parentsurveycode = 1 and questions.qnumber = 1 order by choices.sequence"
			   ,"data" : []
			}		

			,"14" : {
				"query" : "select p.ProjectID, p.ProjectDescription,p.FloatType,p.FloatHours,*, rf.Description as FrequencyDescription from Project p left join RouteFrequency rf on p.FrequencyID = rf.FrequencyID where p.CanRepSchedule = 1 and p.ProjectID in (select distinct ProjectID from ProjectStore )order by p.ProjectDescription asc"
			   ,"data" : []
			}
			
			,"15" : {
				"query" : "select c.chainname, s.storename, p.canrepschedule, p.floattype, p.floathours, p.StartTime, p.projectcode, p.ProjectTypeID, sc.TargetStart, sc.TargetEnd, sc.TimeStart, sc.TimeEnd from Chains c inner join stores s on s.chainid=c._id inner join Schd_CallSchedule sc on sc.StoreID=s._id inner join Project p on p.ProjectID=sc.ProjectID where sc.ScheduleID = 1"
			   ,"data" : []
			}			

			,"16" : {
				"query" : "select s._id, sc.ScheduleID, sc.TargetStart, sc.TargetEnd, st.StatusDesc, c.chainname, s.storename, p.ProjectCode  from Schd_CallSchedule sc inner join stores s on sc.StoreID=s._id inner join Chains c on c._id = s.chainid inner join Schd_CallScheduleStatusCodes st on st.StatusID=sc.Status inner join Project p on p.ProjectID = sc.ProjectID inner join Schd_SurveySchedule ssc on ssc.ScheduleID = sc.ScheduleID"
			   ,"data" : []
			}			

			,"17" : {
				"query" : "select s._id, s.surveycode, s.title from surveys s inner join Schd_SurveySchedule sc on sc.SurveyID=s._id where sc.ScheduleID=1"
			   ,"data" : []
			}			

			,"18" : {
				"query" : "select FirstName,LastName from Contacts where ContactID = 1 or ContactID In(Select ContactID From ContactStore Where StoreID = 1)"
			   ,"data" : []
			}			

			,"20" : {
				"query" : "select stores.* from stores where ChainCode = 1 and StoreNumber in (select vhStoreNumber from vhistory where vhChainCode=1) order by cast(StoreNumber as integer) asc"
			   ,"data" : []
			}

		    ,"27" : {
				"query" : "Select stores._id,stores.storenumber, stores.storename,Chains.chaincode From Stores Inner Join Chains On Stores.chainid = Chains._id where Stores._id= 1"
			   ,"data" : []			
			}

		    ,"28" : {
				"query" : "select * from vhistory where vhchaincode=1 and vhstorenumber=1"
			   ,"data" : []			
			}

			//,"testOnly" : "2"
			//test if primary key is working on insert statements
		    ,"29" : {
			
				"testFn" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS LoginSignature";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table LoginSignature(LoginID int primary key, StoreID int,LoginTime text, Signature text)";
					
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "Insert Into LoginSignature (LoginID, StoreID,LoginTime, Signature) values(1,1,'2012-09-04 12:00:00', 'C:\img.jpg')";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					query = "Insert Into LoginSignature (LoginID, StoreID,LoginTime, Signature) values(1,1,'2012-09-04 12:00:00', 'C:\img.jpg')";
					this.executeReader(query, crcDB, function(t, r_or_e){
						assertTrue(
									r_or_e instanceof HPI.SQLError
							&&	r_or_e.code == HPI.SQLError.DATABASE_ERR
						);						
					});
					
					query = "SELECT * FROM LoginSignature;";
					this.executeReader(query, crcDB, function(t, r_or_e){
						
						assertTrue(
									r_or_e instanceof HPI.SQLResultSet
							&&	r_or_e.rows.length == 1
						);
						
					});
					
					
				}

			}

			//,"testOnly" : "29a"
			//check if auto-increment is working on insert statements
			,"29a" : {
			
				"testFn" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS LoginSignature";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table LoginSignature(LoginID int primary key autoincrement, StoreID int,LoginTime text, Signature text)";
					
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "Insert Into LoginSignature (StoreID,LoginTime, Signature) values(1, '2012-09-04 12:00:00', 'C:\img.jpg')";
					this.executeReader(query, crcDB, function(t, r_or_e){
						
						assertTrue(
									r_or_e instanceof HPI.SQLResultSet
							&&	r_or_e.insertId == 1
						);

					});

					query = "Insert Into LoginSignature (StoreID,LoginTime, Signature) values(1, '2012-09-04 12:00:00', 'C:\img.jpg')";
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						assertTrue(
									r_or_e instanceof HPI.SQLResultSet
							&&	r_or_e.insertId == 2	
						);
						
					});
					
					query = "SELECT * FROM LoginSignature;";
					this.executeReader(query, crcDB, function(t, r_or_e){						
						
						assertTrue(
									r_or_e instanceof HPI.SQLResultSet
							&&	r_or_e.rows.length == 2
							&&	r_or_e.rows.item(0).LoginID == 1
							&&	r_or_e.rows.item(1).LoginID == 2
						);
						
					});
					
					
				}

			}
		
			
			//check if can specify values on autoincrement fields on insert statements
			,"29b" : {
			
				"testFn" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS LoginSignature";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table LoginSignature(LoginID int primary key autoincrement, StoreID int,LoginTime text, Signature text)";
					
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "Insert Into LoginSignature (LoginID, StoreID,LoginTime, Signature) values(1, 1, '2012-09-04 12:00:00', 'C:\img.jpg')";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					query = "Insert Into LoginSignature (LoginID,StoreID, LoginTime, Signature) values(2, 1, '2012-09-04 12:00:00', 'C:\img.jpg')";
					this.executeReader(query, crcDB, function(t, r_or_e){
						assertTrue(
									r_or_e instanceof HPI.SQLResultSet
							&&	r_or_e.insertId == 2	
						);
					});
					
					query = "SELECT * FROM LoginSignature;";
					this.executeReader(query, crcDB, function(t, r_or_e){
						
						assertTrue(
									r_or_e instanceof HPI.SQLResultSet
							&&	r_or_e.rows.length == 2
							&&	r_or_e.rows.item(0).LoginID == 1
							&&	r_or_e.rows.item(1).LoginID == 2
						);
						
					});
					
					
				}
				
			}
			
			
			//check if can correctly get/remember last insert id based on previous inserts
			,"29c" : {
			
				"testFn" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS LoginSignature";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table LoginSignature(LoginID int primary key autoincrement, StoreID int,LoginTime text, Signature text)";
					
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "Insert Into LoginSignature (LoginID, StoreID,LoginTime, Signature) values(5, 1, '2012-09-04 12:00:00', 'C:\img.jpg')";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					query = "Insert Into LoginSignature (StoreID, LoginTime, Signature) values(1, '2012-09-04 12:00:00', 'C:\img.jpg')";
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						assertTrue(
									r_or_e instanceof HPI.SQLResultSet
							&&	r_or_e.insertId == 6
						);
						
					});
					
					query = "Insert Into LoginSignature (LoginID, StoreID, LoginTime, Signature) values(6, 1, '2012-09-04 12:00:00', 'C:\img.jpg')";
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						assertTrue(
									r_or_e instanceof HPI.SQLError
							&&	r_or_e.code == HPI.SQLError.DATABASE_ERR
						);
						
					});
					
					query = "SELECT * FROM LoginSignature;";
					this.executeReader(query, crcDB, function(t, r_or_e){
						//console.log(r_or_e);
						assertTrue(
									r_or_e instanceof HPI.SQLResultSet
							&&	r_or_e.rows.length == 2
							&&	r_or_e.rows.item(0).LoginID == 5
							&&	r_or_e.rows.item(1).LoginID == 6
						);
						
					});
					
					
				}
			
			}
			
			//,"testOnly" : "29d"
			//check if not null is working on insert statements
			,"29d" : {
			
				"testFn" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS LoginSignature";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table LoginSignature(LoginID int primary key autoincrement, StoreID int not null,LoginTime text, Signature text)";					
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "Insert Into LoginSignature (logintime, sIgnature) values('2012-09-04 12:00:00', 'C:\img.jpg')";
					this.executeReader(query, crcDB, function(t, r_or_e){							
							assertTrue(
										r_or_e instanceof HPI.SQLError
								&&	r_or_e.code == HPI.SQLError.DATABASE_ERR
							);
					});
					
					query = "SELECT * FROM LoginSignature";
					this.executeReader(query, crcDB, function(t, r_or_e){
							assertTrue(
										r_or_e instanceof HPI.SQLResultSet
								&&	r_or_e.rows.length == 0
							);
					});
					
				}
			
			}
			
			
			//check if field list and value list are equal
			//,"testOnly" : "29e"
			,"29e" : {
			
				"testFn" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS LoginSignature";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table LoginSignature(LoginID int primary key autoincrement, StoreID int not null,LoginTime text, Signature text)";					
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "Insert Into LoginSignature (logintime, sIgnature) values(1, '2012-09-04 12:00:00', 'C:\img.jpg')";
					this.executeReader(query, crcDB, function(t, r_or_e){
							assertTrue(
										r_or_e instanceof HPI.SQLError
								&&	r_or_e.code == HPI.SQLError.SYNTAX_ERR
							);
					});
					
					query = "SELECT * FROM LoginSignature";
					this.executeReader(query, crcDB, function(t, r_or_e){
							assertTrue(
										r_or_e instanceof HPI.SQLResultSet
								&&	r_or_e.rows.length == 0
							);
					});
					
				}
			
			}
			
			//,"testOnly" : "36"
			//test basic update
		    ,"36" : {
	
				"testFn" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS EmployeeVehicle";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table EmployeeVehicle(Vehicleid int primary key, Vehiclename text, Active int)";					
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "Insert Into EmployeeVehicle values(2, 'V2', 0)";
					this.executeReader(query, crcDB, function(t, r_or_e){						
					});

					query = "Insert Into EmployeeVehicle values(1, 'V1', 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){						
					});

					query = "Insert Into EmployeeVehicle values(3, 'V3', 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){						
					});
					
					query = "update EmployeeVehicle set Active= 0 where VehicleID= 1";
					this.executeReader(query, crcDB, function(t, r_or_e){
							//console.log(r_or_e);
							assertTrue(
										r_or_e instanceof HPI.SQLResultSet
								&&	r_or_e.rowsAffected == 1
							);
					});
					
					query = "SELECT * FROM EmployeeVehicle WHERE VehicleID = 1";
					this.executeReader(query, crcDB, function(t, r_or_e){
							assertTrue(
										r_or_e instanceof HPI.SQLResultSet
								&&	r_or_e.rows.length == 1
								&&	r_or_e.rows.item(0).Active == 0
							);
					});
					
					query = "update EmployeeVehicle set Vehiclename = 'new vehicle name', Active = 1 where Active = 0 and (vehiclename  = 'V1' or vehiclename = 'V2')";
					this.executeReader(query, crcDB, function(t, r_or_e){
							assertTrue(
										r_or_e instanceof HPI.SQLResultSet
								&&	r_or_e.rowsAffected == 2
							);
					});
					

					query = "SELECT * FROM EmployeeVehicle WHERE Vehiclename = 'new vehicle name'";
					this.executeReader(query, crcDB, function(t, r_or_e){
							assertTrue(
										r_or_e instanceof HPI.SQLResultSet
								&&	r_or_e.rows.length == 2
								&&	r_or_e.rows.item(0).Vehiclename == 'new vehicle name' 
								&&	r_or_e.rows.item(1).Vehiclename == 'new vehicle name'
								&&	r_or_e.rows.item(0).Active == 1 
								&&	r_or_e.rows.item(1).Active == 1
							);
					});
					
				}
				
			}
			
			//test if updating a field with used PK value will cause exception
			,"36a" : {
			
				"testFn" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS EmployeeVehicle";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table EmployeeVehicle(Vehicleid int primary key, Vehiclename text, Active int)";					
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "Insert Into EmployeeVehicle values(2, 'V2', 0)";
					this.executeReader(query, crcDB, function(t, r_or_e){						
					});

					query = "Insert Into EmployeeVehicle values(1, 'V1', 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){						
					});

					query = "Insert Into EmployeeVehicle values(3, 'V3', 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){						
					});
					
					query = "update EmployeeVehicle set Vehicleid = 2 where Vehiclename= 'V1'";
					this.executeReader(query, crcDB, function(t, r_or_e){
							assertTrue(
										r_or_e instanceof HPI.SQLError
								&&	r_or_e.code == HPI.SQLError.DATABASE_ERR
							);
					});

				}
				
			}
			
			//test if updating a non-null field to null will cause exception
			,"36b" :{
			
				"testFn" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS EmployeeVehicle";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table EmployeeVehicle(Vehicleid int primary key, Vehiclename text not null, Active int)";					
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "Insert Into EmployeeVehicle values(2, 'V2', 0)";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					query = "Insert Into EmployeeVehicle values(1, 'V1', 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					query = "Insert Into EmployeeVehicle values(3, 'V3', 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "update EmployeeVehicle set Vehiclename = NULL where Vehicleid= 1";
					this.executeReader(query, crcDB, function(t, r_or_e){
							assertTrue(
										r_or_e instanceof HPI.SQLError
								&&	r_or_e.code == HPI.SQLError.DATABASE_ERR
							);
					});

				}
			
			}
			
			//,"testOnly" : "36c"
			
			//test if updating an auto inc field will update the autoincrement id
			,"36c" :{
			
				"testFn" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS EmployeeVehicle";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table EmployeeVehicle(Vehicleid int primary key autoincrement, Vehiclename text not null, Active int)";					
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "Insert Into EmployeeVehicle values(2, 'V2', 0)";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					query = "Insert Into EmployeeVehicle values(1, 'V1', 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					query = "Insert Into EmployeeVehicle values(3, 'V3', 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "update EmployeeVehicle set Vehicleid = 4 where Vehicleid= 1";
					this.executeReader(query, crcDB, function(t, r_or_e){
					});
					
					query = "Insert Into EmployeeVehicle(Vehiclename, Active) values('V5', 0)";
					this.executeReader(query, crcDB, function(t, r_or_e){
							assertTrue(
										r_or_e instanceof HPI.SQLResultSet
								&&	r_or_e.insertId == 5
							);
					});
					
					query = "SELECT * FROM EmployeeVehicle WHERE VehicleId = 5";
					this.executeReader(query, crcDB, function(t, r_or_e){
							assertTrue(
										r_or_e instanceof HPI.SQLResultSet
								&&	r_or_e.rows.item(0).Vehiclename == 'V5'
								&&	r_or_e.rows.length == 1
							);
					});					

				}
			
			}
			
			
			//test delete
			,"30" : {
				
				"testFn" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS EmployeeVehicle";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table EmployeeVehicle(Vehicleid int primary key, Vehiclename int not null, Active int)";					
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "Insert Into EmployeeVehicle values(2, 'V2', 0)";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					query = "Insert Into EmployeeVehicle values(1, 'V1', 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					query = "Insert Into EmployeeVehicle values(3, 'V3', 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "DELETE FROM EmployeeVehicle WHERE VehicleID = 1";
					this.executeReader(query, crcDB, function(t, r_or_e){
							assertTrue(
										r_or_e instanceof HPI.SQLResultSet
								&&	r_or_e.insertId ==1
							);
					});
					
					//check if really deleted
					query = "SELECT * FROM EmployeeVehicle WHERE VehicleId = 1";
					this.executeReader(query, crcDB, function(t, r_or_e){							
							assertTrue(
										r_or_e instanceof HPI.SQLResultSet
								&&	r_or_e.rows.length == 0
							);
					});
					
					//check the other data
					query = "SELECT * FROM EmployeeVehicle";
					this.executeReader(query, crcDB, function(t, r_or_e){							
						assertTrue(
									r_or_e instanceof HPI.SQLResultSet
							&&	r_or_e.rows.length == 2
							&&	r_or_e.rows.item(0).Vehicleid == 2
							&&	r_or_e.rows.length == 2
							&&	r_or_e.rows.item(1).Vehicleid == 3								
						);
					});
					
					//check if we can again re-use the id
					query = "Insert Into EmployeeVehicle values(1, 'V1', 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){
						assertTrue(
									r_or_e instanceof HPI.SQLResultSet
							&&	r_or_e.rows.insertId == 1
							&&	r_or_e.rows.rowsAffected == 1
						);
					});
					
				}
				
			}
			
			//test this specific syntactic style in delete
			,"30a" : {

				"testFn" : function(){
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS appstatus";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table appstatus(name text, value text)";
					
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						query = 'INSERT INTO appstatus (name, value) VALUES ' +
									'("CHAIN_NUMBER", "v1")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
						query = 'INSERT INTO appstatus (name, value) VALUES ' +
									'("NOT_TO_BE_INCLUDED", "v3")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO appstatus (name, value) VALUES ' +
									'("STORE_ID", "v2")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
					});
					
					var query = "delete from appstatus where Name in ('CHAIN_NUMBER','STORE_ID')";
					this.executeReader(query, crcDB, function(t, r_or_e){
						//console.log(r_or_e);
						assertTrue(
									r_or_e instanceof HPI.SQLResultSet
							&&	r_or_e.rowsAffected == 2
						);
					});
					
				}
			
			}
			
			//,"testOnly" : "30b"
			,"30b" : {
				//"query" : "delete from Logout where LogoutID > 0 and LogoutID in (select LogoutID from StoreActivity where LoginID > 0 and LogoutID > 0)"
			   //,"data" : []
				"testFn" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS Logout";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					var query = "DROP TABLE IF EXISTS StoreActivity";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					
					var me = this;
					
					query = "create table Logout (LogoutID int not null, LogoutTime datetime, StoreID int, SignerName text)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
				
					query = "create table StoreActivity (StoreID int, LogoutID int not null, LoginID int)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "INSERT INTO Logout(LogoutID, LogoutTime, StoreID, SignerName)" +
								"VALUES(0, '12:00', 1, 's1')";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "INSERT INTO Logout(LogoutID, LogoutTime, StoreID, SignerName)" +
								"VALUES(1, '12:00', 1, 's1')";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "INSERT INTO Logout(LogoutID, LogoutTime, StoreID, SignerName)" +
								"VALUES(2, '12:00', 1, 's1')";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					
					query = "INSERT INTO StoreActivity(StoreID, LogoutID, LoginID) VALUES(1, 0,0)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "INSERT INTO StoreActivity(StoreID, LogoutID, LoginID) VALUES(2, 1,1)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					
					
					//query = "SELECT * from Logout where LogoutID > 0 and LogoutID in (select LogoutID from StoreActivity where LoginID > 0 and LogoutID > 0)";
					//query = "select LogoutID from StoreActivity where LoginID > 0 and LogoutID > 0";
					query = "DELETE * from Logout where LogoutID > 0 and LogoutID in (select LogoutID from StoreActivity where LoginID > 0 and LogoutID > 0)";
					this.executeReader(query, crcDB, function(t, r_or_e){
							assertTrue(
										r_or_e instanceof HPI.SQLResultSet
								&&	r_or_e.rowsAffected ==  1
							);
					});
					
					//verify the delete
					query = "SELECT * FROM LogOut";
					this.executeReader(query, crcDB, function(t, r_or_e){
							assertTrue(
										r_or_e instanceof HPI.SQLResultSet
								&&	r_or_e.rows.length ==  2
								&&	r_or_e.rows.item(0).LogoutID ==  0
								&&	r_or_e.rows.item(1).LogoutID ==  2
							);
					});
					


					
				}
			}		
			
			//,"testOnly" : "30c"
			,"30c" : {
			
				"testFn" : function(){
				
					this.initDB();
					
					var query = "DROP TABLE IF EXISTS appstatus";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var me = this;
					
					query = "create table appstatus(name text, value text)";
					
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						query = 'INSERT INTO appstatus (name, value) VALUES ' +
									'("CHAIN_NUMBER", "v1")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
						
						query = 'INSERT INTO appstatus (name, value) VALUES ' +
									'("NOT_TO_BE_INCLUDED", "v1")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});

						query = 'INSERT INTO appstatus (name, value) VALUES ' +
									'("STORE_ID", "v1")';

						me.executeReader(query, crcDB, function(_t, _r_or_e){});
					});
					
					var me = this;
					var query = "delete from appstatus where value = 'v1'";
					this.executeReader(query, crcDB, function(t, r_or_e){
						
						query = "select * from appstatus";
						me.executeReader(query, crcDB, function(t, r_or_e){
							console.log(r_or_e);
						});
						
					});
					


					
				}
				
			
			}
			
			//test an insert in this form
			
			//,"testOnly" : "35a"
			,"35a" : {
			
			
				"testFn" : function(){
				
					this.initDB();
					/*
					var query = "drop table if exists surveys;";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					var query = "drop table if exists surveystores;";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					
					var me = this;
					
					query = "create table surveys (_id integer not null primary key autoincrement, title text, surveycode text, questioncount integer, startdate text, enddate text, mandatory integer, skipable integer, canaudit integer, activationtype integer);";
					this.executeReader(query, crcDB, function(t, r_or_e){});
				
					query = "create table surveystores (_id integer not null primary key autoincrement, sschainnumber text, ssstorenumber text, sssurveycode text); ";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = 'insert into surveys( _id, title, surveycode, questioncount, startdate, enddate, mandatory, skipable, canaudit, activationtype) values ("41159","!Skip to my Lou!","7257","5","2011-03-17 00:00:00.000","2099-12-31 23:59:59.000","0","0","1","");'
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = '  insert into surveys( _id, title, surveycode, questioncount, startdate, enddate, mandatory, skipable, canaudit, activationtype) values ("40021","!test3542","100123","3","2010-07-29 00:00:00.000","2099-12-31 23:59:59.000","0","0","0","");';
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					//verify the delete
					query = "SELECT * FROM surveys;";
					this.executeReader(query, crcDB, function(t, r_or_e){
						//console.log(r_or_e);
					});
					
					query = 'insert into surveystores( sschainnumber, ssstorenumber, sssurveycode ) select "50","3029", s.surveycode from surveys s where s.surveycode in (7257, 100123) '
					this.executeReader(query, crcDB, function(t, r_or_e){
						//console.log(r_or_e);
					});

					query = "SELECT * FROM surveystores";
					this.executeReader(query, crcDB, function(t, r_or_e){
							assertTrue(
								r_or_e.rows.length == 2
							);
					});
					*/
				  query = "drop table if exists questions; "
				  this.executeReader(query, crcDB, function(t, r_or_e){});
				  query = "create table if not exists questions(_id integer not null primary key autoincrement, parentsurveycode text, qnumber integer, qtext text, qtype text, lvalue real, hvalue real, maxlength integer, decimalposition integer, numchoices integer, qstartdate text, qenddate text, instructiontext text, instructionlocation text, documenturl text, isdroplist integer, commentsrequiredanswer integer, filefilter text, maxphotos integer, skipyes integer, skipno integer, auditscore integer, MaxQuestion integer, MinQuestion integer, QuestionLabel text); "
				this.executeReader(query, crcDB, function(t, r_or_e){});	
					query = 'insert into questions( _id, parentsurveycode, qnumber, qtext, qtype, lvalue, hvalue, maxlength, decimalposition, numchoices, qstartdate, qenddate, instructiontext, instructionlocation, documenturl, isdroplist, commentsrequiredanswer, filefilter, maxphotos, skipyes, skipno, auditscore, MaxQuestion, MinQuestion, QuestionLabel) values ("76323","4111","10","Example of a date question:  Please enter the date of next planned visit to this store.","Date","122011","5222011","0","0","1","1999-01-01 00:00:00.000","2099-01-01 00:00:00.000","","0", "","0","-1","","0","0","0","0", "-1","-1","");'
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
				}
			
			}
			
			
		    ,"35" : {
				"query" : "Update SurveyPicImages Set AnswerID = 1 Where qnumber = 1 And surveycode = 1 And LocationID = 1 And ProductID = 1"
			   ,"data" : []			
			}

			
		    ,"30" : {
				"query" : "delete from appstatus where Name in ('CHAIN_NUMBER','STORE_ID','STORE_NAME','STORE_NUMBER','LOGIN_ID','SURVEY_ID','SURVEY_NUMBER','TEMP_SESSION_ID','CUR_ANSWER_ID')"
			   ,"data" : []
			}

		    ,"31" : {
				"query" : "Delete From SurveyPicImages Where surveycode = 1  And qnumber = 1"
			   ,"data" : []			
			}

		    ,"32" : {
				"query" : "delete from Logout where LogoutID > 0 and LogoutID in (select LogoutID from StoreActivity where LoginID > 0 and LogoutID > 0)"
			   ,"data" : []			
			}			

		    ,"33" : {
				"query" : "delete from SurveyAuditAnswerDetail where SessionID in (select SessionID from SurveyAuditAnswerSession where PushedAnswerID < 0)"
			   ,"data" : []			
			}			

		    ,"34" : {
				"query" : "delete from SurveyAuditAnswerSession where PushedAnswerID < 0"
			   ,"data" : []			
			}
		  			
		    ,"37" : {
				"query" : "Create Table LoginSignature (_id integer not null primary key autoincrement, LoginID text, StoreID text,LoginTime text, Signature text)"
			   ,"data" : []			
			}

		    ,"38" : {
				"query" : "create table Logout (LogoutID int not null, LogoutTime datetime, StoreID int, SignerName text, SignerComment text, Latitude text, Longitude text)"
			   ,"data" : []			
			}
			
		    ,"39" : {
				"query" : "Drop Table LoginSignature"
			   ,"data" : []			
			}
			
		    ,"40" : {
				"query" : "drop table if exists SurveyAuditAnswerSession"
			   ,"data" : []			
			}
			
			,"41" : {
				"query" : "Create table if not exists SurveyPicImages(_id integer not null primary key autoincrement, surveycode text)"
			}

			,"42" : {
				"query" : "select ID from messages where [Read] = 1"
			}

			,"43" : {
				"query" : "select ID from messages where [Read]  IN (SELECT * FROM a)"
			}
			
			,"44" : {
				"query" : "select ID, [a] from messages where [Read]  IN ('a','b')"
			}

			,"45" : {
				"query" : "SELECT * FROM a order by field1 collate nocase asc"
			}

			//,"testOnly" : "46"
			,"46" : {
				
				"testFn" : function(){
					
					this.initDB();
					
					var query = "";
					
					query = "drop table if exists tbl1";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "create table if not exists tbl1(field1 text, field2 int)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
				
					query = "INSERT INTO tbl1 VALUES('Trialssss', 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "INSERT INTO tbl1 VALUES('aa_survey replica', 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
				
					
					query = "SELECT field1 FROM tbl1 ORDER BY field1 COLLATE NOCASE ASC";
					this.executeReader(query, crcDB, function(t, r_or_e){
						console.log(r_or_e);
						return;
						assertTrue(
										r_or_e instanceof HPI.SQLResultSet
								&&	r_or_e.rows.length ==  2
								&&	r_or_e.rows.item(0).field1 ==  'a'
								&&	r_or_e.rows.item(1).field1 ==  'B'
							);
					});
					
				}
			}
			
			,"47" : {
				"query" : "delete from Login where LoginID = -1"
			}
			
			,"48" : {
				"query" : "Insert Into StoreActivity (StoreID, LoginID, LogoutID) values(406530,-1,-1001)"
			}
		
			//,"testOnly" : "49"		
			//test DATETIME function
			,"49" : {
			
				"testFn" : function(){
				
					this.initDB();
				
					query = "drop table if exists tbl1; ";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					query = "drop table if exists tbl2; ";					
					this.executeReader(query, crcDB, function(t, r_or_e){});					
					query = "drop table if exists tbl3; ";					
					this.executeReader(query, crcDB, function(t, r_or_e){});
					query = "drop table if exists tbl4; ";					
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "create table if not exists  tbl1(field1 text, field2 int); ";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "create table if not exists  tbl2(field1 text, field2 int); ";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "create table if not exists  tbl3(field1 int, field2 int); ";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "create table if not exists  tbl4(field1 int, field2 int, field3 int); ";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "INSERT INTO tbl1 VALUES('2013-01-01', 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "INSERT INTO tbl2 VALUES('2013-01-01', 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					query = "INSERT INTO tbl2 VALUES('2013-01-02', 2)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "INSERT INTO tbl3 VALUES(1, 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					query = "INSERT INTO tbl4 VALUES(1, 1, 2)";
					this.executeReader(query, crcDB, function(t, r_or_e){});					
					query = "INSERT INTO tbl4 VALUES(1, 1, 1)";
					this.executeReader(query, crcDB, function(t, r_or_e){});					
					
					query = "SELECT datetime(t1.field1) as 'afield1' FROM tbl1 t1 INNER JOIN tbl2 t2 ON t1.field2 = t2.field2 " +
						"WHERE t2.field2 = 1 AND DATETIME(t1.field1) = DATETIME('2013-01-01') group by t1.field1;";
					this.executeReader(query, crcDB, function(t, r_or_e){
						console.log(r_or_e);
					});
					
					
					query = "SELECT t4.field3 FROM tbl3 t3 INNER JOIN tbl4 t4 ON t3.field1 = t4.field1 " +
						"ORDER BY field3";
					this.executeReader(query, crcDB, function(t, r_or_e){
						console.log(r_or_e);
					});
					
					
					// query = "SELECT t1.field1, t2.field2 FROM tbl1 t1, tbl2 t2";
					// this.executeReader(query, crcDB, function(t, r_or_e){
						// console.log(r_or_e);
					// });
					
					/*
					"select (Select '>>' from surveyanswersession Where surveycode=s.surveycode And StoreID = 25866 and StoreActivityID = -1001)As Ans, s.title " +
					"from surveys s inner join surveystores st on s.surveycode=st.sssurveycode" +
					"where  st.sschainnumber= 30 and st.ssstorenumber = 42" +
					"and (Datetime(s.startdate) <= Datetime('2013-03-20 13:15:00.000')) group by s.title order by s.title";
					*/
					
					/*
			    "select distinct (Select '>>' from SurveyAnswerSession Where LocationID=sl.LocationID And surveyid = 41691)As Ans, " +
				"sl.LocationID, ln.LocationName, sas.SessionID, sl.Sequence, sl.AllowRepeat " +
				"from SurveyLocation sl  " + 
				"inner join LocationName ln on ln.LocationID = sl.LocationID  " +
				"left join SurveyAnswerSession sas on " +
				"sas.LocationID = sl.LocationID and sas.SessionID <> sas.SessionID and sas.SurveyID = sl.SurveyID and sas.StoreID = sl.StoreID  " +
				"where sl.StoreID=25866 and sl.SurveyID = 41691 " +
				"order by sl.Sequence asc";
					*/
				}
			
			}
		
		
			//"create table if not exists test"
			//,"testOnly" : "49"
			,"50" : {
			
				"testFn" : function(){
					
					this.initDB();
				
					var query = "CREATE TABLE IF NOT EXISTS AutoSave  (StoreID text, SurveyID text, QuestionNumber text, QuestionID text, LocationID text, ProductID text, Answer text, Comment text)";
					this.executeReader(query, crcDB, function(t, r_or_e){
						console.log('a');
					});
				
				
				}
			}
		
			//,"testOnly" : "51"
			,"51" : {
			
				"testFn" : function(){
					
					this.initDB();
				
					var query = "DROP TABLE IF EXISTS surveyanswersession";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "CREATE TABLE surveyanswersession (storeid text, surveyid text, surveycode text,ProductID int, StoreActivityID int)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					var query = "INSERT INTO surveyanswersession VALUES('1', '1', '1', '1', 1001);";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					
					var query = "DROP TABLE IF EXISTS surveystores";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "CREATE TABLE surveystores (sssurveycode text, sschainnumber text, ssstorenumber text)";
					this.executeReader(query, crcDB, function(t, r_or_e){});

					var query = "INSERT INTO surveystores VALUES('1', '1', '1');";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "INSERT INTO surveystores  VALUES('2', '2', '2');";
					this.executeReader(query, crcDB, function(t, r_or_e){});					
					
					var query = "DROP TABLE IF EXISTS surveys";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					var query = "CREATE TABLE surveys(title text, surveycode text, mandatory text)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "INSERT INTO surveys  VALUES('a', '1', '1');";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "INSERT INTO surveys  VALUES('b', '2', '1');";
					this.executeReader(query, crcDB, function(t, r_or_e){});							
					
					var query = "select "					
					+ "s.title from surveys s inner join surveystores st on s.surveycode=st.sssurveycode and  st.sschainnumber= '1' and st.ssstorenumber = '1' "
					//+ "where   st.sschainnumber= 30 and st.ssstorenumber = 42"
					//+ "and (Datetime(s.startdate) <= Datetime('2013-03-20 13:15:00.000')) group by s.title order by s.title";
					
					this.executeReader(query, crcDB, function(t, r_or_e){
						console.log(r_or_e.message);
					});
					
					/*
					var query = "select "
					+ "(Select '>>' from surveyanswersession Where surveycode=s.surveycode And StoreID = 1 and StoreActivityID = -1001)As Ans "
					+ " from surveystores st ";
					
					this.executeReader(query, crcDB, function(t, r_or_e){
						console.log(r_or_e.message);
					});
					*/
					//ExecuteReaderWithSingleCallback(query, crcDB, function(t, r_or_e){ console.log('a'); });
				}
			
			}
		
		
			
			//test if IS NULL is working
			,"52" : {
			
				"testFn" : function(){
					
					this.initDB();
				
					var query = "DROP TABLE IF EXISTS tbl1";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "CREATE TABLE tbl1 (fld1 int, fld2 int)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					var query = "INSERT INTO tbl1 VALUES(1, null);";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "INSERT INTO tbl1 VALUES(1, 1);";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "select *, (fld2 is null) as 'x' from tbl1 where fld2 is null;";
					this.executeReader(query, crcDB, function(t, r_or_e){
					
						 assertTrue(
										r_or_e instanceof HPI.SQLResultSet
								&&	r_or_e.rows.length == 1
								&&	r_or_e.rows.item(0).x == true
								&&	r_or_e.rows.item(0).fld2 == null
						 );
					
					});
					
				}
				
			}
			
			//test if IS NOT NULL is working
			,"53" : {
			
				"testFn" : function(){
					
					this.initDB();
				
					var query = "DROP TABLE IF EXISTS tbl1";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "CREATE TABLE tbl1 (fld1 int, fld2 int)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					var query = "INSERT INTO tbl1 VALUES(1, null);";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "INSERT INTO tbl1 VALUES(1, 1);";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "select *, (fld2 is not null) as 'x' from tbl1 where fld2 is not null;";
					this.executeReader(query, crcDB, function(t, r_or_e){
						
						console.log(r_or_e);
						assertTrue(
										r_or_e instanceof HPI.SQLResultSet
								&&	r_or_e.rows.length == 1
								&&	r_or_e.rows.item(0).x == true
								&&	r_or_e.rows.item(0).fld2 == 1
						 );
					
					});
					
				}
				
			}
			
			//,"testOnly" : "54"
			
			//test if IS operator is working like equals when non-NULL is supplied
			,"54" : {
			
				"testFn" : function(){
					
					this.initDB();
				
					var query = "DROP TABLE IF EXISTS tbl1";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "CREATE TABLE tbl1 (fld1 int, fld2 int)";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					var query = "INSERT INTO tbl1 VALUES(1, null);";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "INSERT INTO tbl1 VALUES(1, 1);";
					this.executeReader(query, crcDB, function(t, r_or_e){});
					
					var query = "select * from tbl1 where fld2 is not 1;";
					this.executeReader(query, crcDB, function(t, r_or_e){
						
						console.log(r_or_e);
						assertTrue(
										r_or_e instanceof HPI.SQLResultSet
								&&	r_or_e.rows.length == 1
								&&	r_or_e.rows.item(0).fld2 == null
						 );
					
					});
					
				}
				
			}
		}

		
	    ,data : function(index, consistent){
		
			if( index === false || index === undefined ){
				return this._data;
			}
			
			if( !this._data[index] ){
				throw new Error("Cannot find index - " + index);
			}
		
			consistent = consistent || true;	
			return consistent ? {index : this._data[index] } : this._data[index];
			
		}
	
	}

}();